I am attempting to create a table that makes use of four consecutive multi-rows (if the reason for why this format has been chosen is important I can add it). I am using the multirow package as well as the shortstack command to execute linebreaks in each row. The text in the table is displaying as it should, but the cell boundaries are behaving as if the table was a group of single line rows.

The code that I am using is as follows:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}

\begin{document}
\begin{tabular}{|c|c|c|c|}
\hline
\multirow{3}{*}{Name} & \multirow{3}{*}{Website} & \multirow{3}{*}{\shortstack[c]{e-mail \\ phone}} & \multirow{3}{*}{\shortstack{line 1 \\ line 2 \\ line 3}} \\
\hline
\end{tabular}
\end{document}

The result is sad:

enter image description here

Due to the simplicity of the input, I'm quite stumped. I would be greatly appreciative if someone can tell me why this is happening or recommend a smoother way of accomplishing my goal.

Thanks!

  • 2
    Welcome to TeX.SE! What is the role of \multirow in a table that only has one row? – marmot Sep 22 at 22:37
  • @marmot, there will be many of these multirow rows. I was using a singular row to illustrate my issue. – justathought Sep 22 at 23:18
  • 1
    Yes, but this is precisely the reason why it does not work as you want it to work. If you use multirow, you want to make sure that you have multiple rows. At least for the example you show, makecell might be a better choice. (As for the example you do not show, I can't say much since my crystal ball got stolen.;-) – marmot Sep 22 at 23:23
  • 1
    I misunderstood your first comment! having read your answer I understand the meaning of "one row". Thank you! – justathought Sep 22 at 23:32
up vote 4 down vote accepted

From "the text is displaying as it should" I take that you are looking for makecell.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{makecell}

\begin{document}
\begin{tabular}{|c|c|c|c|}
\hline
Name & Website & 
\makecell{e-mail \\ phone} & 
\makecell{line 1 \\ line 2 \\ line 3} \\
\hline
\end{tabular}
\end{document}

enter image description here

Of course, you can do the same with multirow provided you really have multiple rows.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}

\begin{document}
\begin{tabular}{|c|c|c|c|}
\hline
\multirow{3}{*}{Name} & \multirow{3}{*}{Website} & \multirow{3}{*}{\shortstack[c]{e-mail \\ phone}} & line 1 \\ 
& & & line 2 \\ 
& & & line 3 \\
\hline
\end{tabular}
\end{document}

enter image description here

Possible issues with \shortstack are discussed in egreg's nice answer.

  • Thank you, \makecell is exactly what I need. I will also change the title of my post to something more humble. – justathought Sep 22 at 23:29

The following example shows why \shortstack should not be used and proposes a solution for your problem.

\documentclass{article}

\newcommand{\notshortstack}[2][l]{%
  \begin{tabular}{@{}#1@{}}#2\end{tabular}%
}

\begin{document}

% why \shortstak should not be used
\fbox{\shortstack{line 1 \\ aaa \\ line 3}}
\fbox{\shortstack{ling 1 \\ aaa \\ line 3}}

\bigskip

\begin{tabular}{|c|c|c|c|}
\hline
Name & Website & \notshortstack[c]{e-mail \\ phone} &
\notshortstack{line 1 \\ line 2 \\ line 3} \\
\hline
\end{tabular}
\end{document}

enter image description here

  • +1 Ironically, \longstack would be shorter than \nonshortstack ;-) (And isn't that (more or less) what \makecell does? – marmot Sep 22 at 22:52
  • @marmot makecell can do much more; it mostly depends on what one has to do. – egreg Sep 22 at 22:55

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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