3

I am struggling with the following problem. Let's assume I have this sample code:

\documentclass{article}

\usepackage{array, booktabs}
\usepackage{multirow}

\newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}

\begin{document}
\begin{table}
    \centering
    \begin{tabular}{P{2cm} | P{4cm} | P{4cm} | P{2cm}}
        \toprule
        \multirow{2}{*}{\begin{tabular}[c]{@{}c@{}}Line 1\\Line 2\\Line 3\end{tabular}}
        &
        {\begin{tabular}[c]{@{}c@{}}Line 1\\Line 2\\Line 3\end{tabular}}
        &
        {\begin{tabular}[c]{@{}c@{}}Line 1\\Line 2\\Line 3\end{tabular}}
        &
        \multirow{2}{*}{\begin{tabular}[c]{@{}c@{}}Line 1\\Line 2\end{tabular}}
        \\
         & \textit{Lorem ipsum dolor sit} & \textit{Lorem ipsum dolor sit} & \\
        \toprule
        A & Lorem ipsum dolor sit & Lorem ipsum dolor sit & B \\
        \bottomrule 
    \end{tabular}
\end{table}

\end{document}

The following output get's produced:

table

My problem: In the first row, first column I would like to have also the three lines vertically centered. How to achieve this?!

Thank you for your help in advance!

  • 1
    Welcome to TeX.SX! Do you mean first row or (as you use multirow) the first two rows? – TeXnician Mar 28 '18 at 8:10
  • I mean the cell in the first row, first column "as you see it". So I would like to have Line 1 Line 2 Line 3 vertically centered on the whole, as it is for example with Line 1 Line 2 in the cell in the first row, last column. Sorry, maybe I should have chosen different names, so that it's easier to understand... – Joojoo Mar 28 '18 at 8:17
2

You could use \makecell and don't use vertical lines with booktabs:

\documentclass{article}

\usepackage{array, booktabs}
\usepackage{makecell}

\newcolumntype{P}[1]{>{\centering\leavevmode\arraybackslash}p{#1}}

\begin{document}
    \begin{table}
        \centering
        \begin{tabular}{P{2cm}  P{4cm}  P{4cm}  P{2cm}}
            \toprule
            \makecell{Line 1\\Line 2\\Line 3}
            &
            \makecell{Line 1\\Line 2\\Line 3\\ \textit{Lorem ipsum dolor sit}}
            &
            \makecell{Line 1\\Line 2\\Line 3\\ \textit{Lorem ipsum dolor sit}}
            &
            \makecell{Line 1\\Line 2}
            \\      
            \toprule
            A & Lorem ipsum dolor sit & Lorem ipsum dolor sit & B \\
            \bottomrule 
        \end{tabular}
    \end{table}
\end{document}

Is this what you intend?

enter image description here

  • Wow, thanks nice! Such a fast answer and also a solution, which makes the code a lot more readable ;) – Joojoo Mar 28 '18 at 8:28
  • @Joojoo You're welcome! We are always happy to help users who provide a complete minimal working example! – CarLaTeX Mar 28 '18 at 8:29

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.