9

I have a tabularx table with a heading in 2 lines. How can I align vertically to the middle the remaining single line headings?

\documentclass[12pt,a4paper]{article}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tabularx}
\usepackage{blindtext}
\usepackage{booktabs}
\begin{document}
\begin{table}[htb]
\footnotesize
\begin{tabularx}{\linewidth}{cX}
\toprule
\textbf{\shortstack{Line 1\\Line 2}} & \textbf{Head}\\
\midrule
Parameter 1 & \blindtext \\
Parameter 2 & \blindtext \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}

enter image description here

6

What about using makecell?

\documentclass[12pt,a4paper]{article}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tabularx}
\usepackage{blindtext}
\usepackage{booktabs}
\usepackage{makecell}
\begin{document}
    \begin{table}[htb]
        \footnotesize
        \begin{tabularx}{\linewidth}{cX}
            \toprule
            \textbf{\makecell{Line 1\\Line 2}} & \textbf{Head}\\
            \midrule
            Parameter 1 & \blindtext \\
            Parameter 2 & \blindtext \\
            \bottomrule
        \end{tabularx}
    \end{table}
\end{document}

enter image description here

|improve this answer|||||
3

Use a \Centerstack from the stackengine package. Not only does it achieve the desired centering, it gets the line spacing correct (by fixing the baselineskip, rather than the inter-word vertical gap in the manner of \shortstack).

\documentclass[12pt,a4paper]{article}
\usepackage{blindtext}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{tabularx}
\usepackage{blindtext}
\usepackage{booktabs}
\usepackage[usestackEOL]{stackengine}
\begin{document}
\begin{table}[htb]
\footnotesize
\begin{tabularx}{\linewidth}{cX}
\toprule
\textbf{\Centerstack{Line 1\\Line 2}} & \textbf{Head}\\
\midrule
Parameter 1 & \blindtext \\
Parameter 2 & \blindtext \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}

enter image description here

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.