Text FormattingFit and vertically align larger text in a tabular

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
juliendutant
Posts: 14
Joined: Sat Aug 27, 2016 1:46 pm

Fit and vertically align larger text in a tabular

Post by juliendutant »

Hi all,

I'm trying to design a cover head with a large journal title on the left and smaller volume and issue numbers opposite on the right. I've tried to design that with a tabular, but it doesn't seem to handle font size changes well: the larger text is still placed on the same baseline as it would if it was normalize, and hence sticks out of the cell.

Code: Select all

\documentclass{article}
\usepackage{tabularx} % tabularx for automatic full width table
\usepackage{multirow} % multirow for cells that span several rows
\begin{document}

\noindent
\begin{tabularx}{\textwidth}{@{\vrule}X@{\vrule}r@{\vrule}}
\hline
\multirow[t]{2}{*}{{\Huge journal title}} & vol 1\\ \cline{2--2}
							& issue 1\\
\hline
\end{tabularx}

\end{document}
mwe.png
mwe.png (20.12 KiB) Viewed 8743 times
Centering the multirow on the left doesn't help: first, because I want it top aligned (if the cells on the right get bigger, the title should remain top-aligned), and second, because the left cell text can still protrude out of the cell if the font is big enough. Placing the text in a parbox or makebox doesn't help. I use tabularx to get a full width table but the same problem arises with tabular too.

Any suggestions? Do I have to use a tikz picture instead?
Last edited by juliendutant on Sat Jan 23, 2021 5:04 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Fit and vertically align larger text in a tabular

Post by Stefan Kottwitz »

Hi Julien,

a quick fix with \raisebox:

Code: Select all

\documentclass{article}
\usepackage{tabularx} % tabularx for automatic full width table
\usepackage{multirow} % multirow for cells that span several rows
\begin{document}
 
\noindent
\begin{tabularx}{\textwidth}{@{\vrule}X@{\vrule}r@{\vrule}}
\hline
\multirow[t]{2}{*}{\ \raisebox{-\baselineskip}{\Huge Journal title}}
    & vol 1\\ \cline{2--2}
    & issue 1\\
\hline
\end{tabularx}

\end{document}
table.png
table.png (5 KiB) Viewed 8738 times
Stefan
LaTeX.org admin
juliendutant
Posts: 14
Joined: Sat Aug 27, 2016 1:46 pm

Fit an vertically align larger text in a tabular

Post by juliendutant »

Oh nice, thanks Stefan!
juliendutant
Posts: 14
Joined: Sat Aug 27, 2016 1:46 pm

Fit an vertically align larger text in a tabular

Post by juliendutant »

Can we put a value in raisebox that matches the desired size of the font? e.g. \baselineskip is ok for \Huge but not enough for \Large. I think that would have to be something that calculates (desired size of font - baselineskip), with a negative sign to lower the box.
juliendutant
Posts: 14
Joined: Sat Aug 27, 2016 1:46 pm

Fit and vertically align larger text in a tabular

Post by juliendutant »

I've tried this calculation:

raiseby ( height of title - baselineskip)

but no luck: in smaller font sizes it doesn't raise the text enough, in larger ones it raises it too much. See below. I can do manually in the meanwhile, but I'm sure there's a way to compute the right raising value automatically.
mwe.png
mwe.png (35.76 KiB) Viewed 8724 times

Code: Select all

\documentclass{article}

% tabularx for automatic full width table
\usepackage{tabularx}
% multirow for cells that span several rows
\usepackage{multirow}

\begin{document}

\noindent \vrule for info, textblock starts here \dotfill and ends here\vrule
\vskip 2em

\normalsize

\newlength{\titlesize}
\settoheight{\titlesize}{\large journal title}
\newlength{\titleraise}
\setlength{\titleraise}{\baselineskip}
\addtolength{\titleraise}{-\titlesize}

\noindent 
\begin{tabularx}{\textwidth}{@{\vrule}X@{\vrule}r@{\vrule}}
\hline
\multirow[c]{2}{*}{\raisebox{\titleraise}{\large journal title}} & vol 1\\
\cline{2--2}
							& issue 1\\
\hline
\end{tabularx}

\vskip 1em

\footnotesize

\settoheight{\titlesize}{\Huge journal title}
\setlength{\titleraise}{\baselineskip}
\addtolength{\titleraise}{-\titlesize}

\noindent 
\begin{tabularx}{\textwidth}{@{\vrule}X@{\vrule}r@{\vrule}}
\hline
\multirow[c]{2}{*}{\raisebox{\titleraise}{\Huge journal title}} & vol 1\\
\cline{2--2}
							& issue 1\\
\hline
\end{tabularx}

\vskip 1em

\normalsize

\settoheight{\titlesize}{\normalsize journal title}
\setlength{\titleraise}{\baselineskip}
\addtolength{\titleraise}{-\titlesize}

\noindent 
\begin{tabularx}{\textwidth}{@{\vrule}X@{\vrule}r@{\vrule}}
\hline
\multirow[c]{2}{*}{\raisebox{\titleraise}{\normalsize journal title}} & vol 1\\
\cline{2--2}
							& issue 1\\
\hline
\end{tabularx}

\vskip 1em

\settoheight{\titlesize}{\fontsize{48}{54}\selectfont journal title}
\setlength{\titleraise}{\baselineskip}
\addtolength{\titleraise}{-\titlesize}

\noindent 
\begin{tabularx}{\textwidth}{@{\vrule}X@{\vrule}r@{\vrule}}
\hline
\multirow[c]{2}{*}{\raisebox{\titleraise}{\fontsize{48}{54}\selectfont  journal title}} & vol 1\\
\cline{2--2}
							& issue 1\\
\hline
\end{tabularx}

\end{document}
Post Reply