1

I was trying both break lines in the cells of my first column and in some column titles. I've tried the suggestion of using \pbox. But it does not seem to work. I've looked already for some answers and I understand this might be interpreted as a duplicate -- but bear with me, it is really not working. Here is an example of the code that I've been working with:

Observation: I've been trying to do this table in the beamer type of document. One of the answers, though being really helpful, does not work with that type of document -- so I will make it explicit in the code right now. Also, I've have corrected the name of the columns, which weren't in the right order.

\documentclass{beamer}
\usepackage{multirow,bigstrut}
\begin{document}
\frame
{
\frametitle{Table 1}
    \begin{tabular}{|c|c|c|c|c|c|c|}
        \hline
        \textbf{Product} & \textbf{Company}} & \textbf{Temperature} & \textbf{Observations} & \textbf{\pbox{2cm}{Temperature Test\\on Hot Water}} & \textbf{Temperature Test on Cold Water} & \textbf{Consistency} \bigstrut\\
        \hline
        \multirow{2}[4]{*}{\pbox{2cm}{Product \\ 1}} & Company 1 & 13.5 & 84 & 1000.5 & 1000.7 & 1000.8 \bigstrut\\
        \cline{2-7}     & Company 2 & 14.3 & 71 & 1000.2 & 1000.9 & 1000.12 \bigstrut\\
        \hline
    \end{tabular}%
}
end{document}
4
  • Entries in columns marked as l, c or r will never break on its own. You'll have to do this manually, or use an alternative column specification (like p{<len>}).
    – Werner
    Commented Apr 8, 2015 at 17:59
  • If I were to use \begin{tabular}{p{2cm}} it would break after 2cm?
    – John Doe
    Commented Apr 8, 2015 at 20:16
  • Correct... Depending on whether hyphenation is possible after 2cm, or a break in general.
    – Werner
    Commented Apr 8, 2015 at 20:17
  • You can break lines inside multirow if you remove * and use \multirow{2}[4]{2cm}{\centering Product \\ 1}
    – user11232
    Commented Apr 9, 2015 at 0:58

2 Answers 2

2

You can obtain what you wnat very simply with the makecell, which allows form line breaks in cells with the makecell, \multirowcell, \thead and \multirowhead. The bigstrut command is replaced with the \makegapedcells switch, after we've defined the value of cell gapes.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[hmargin = 2cm]{geometry}

\usepackage{array, makecell, multirow, pbox, bigstrut}
\renewcommand\theadfont{\bfseries}
\setcellgapes{5pt}
\begin{document}

\noindent
{\setlength\tabcolsep{4pt}\makegapedcells
\begin{tabular}{|*{7}{c|}}
  \hline
  \thead{Product} & \thead{Temperature} & \thead{Date} & \thead{Observations} & \thead{Temperature Test \\on Hot Water} & \thead{Temperature Test \\on Cold Water} & \thead{Consistency} \\
  \hline
  \multirowcell{2}[-5pt]{Product\\ 1} & Company 1 & 13.5 & 84 & 1000.5 & 1000.7 1000.8 & \\
  \cline{2-7} & Company 2 & 14.3 & 71 & 1000.2 & 1000.9 & 1000.12 \\
  \hline
\end{tabular}}%

\end{document} 

For a beamer document, you can use the \rothead command:

\documentclass{beamer}
\usepackage[utf8]{inputenc}
\usepackage{geometry}

\usepackage{array, makecell, multirow,rotating}
\renewcommand\theadfont{\bfseries}
\renewcommand\theadalign{lb}
\setcellgapes{4pt}
\renewcommand\cellrotangle{40}

\begin{document}
\vspace*{1cm}
{\setlength\tabcolsep{4pt}\makegapedcells
  \setlength{\rotheadsize}{1cm}\footnotesize\centering
  \begin{tabular}{|*{7}{c|}}
    \multicolumn{1}{c}{ \rothead{ \\\rlap{Product}}} & \multicolumn{1}{c}{\rothead{\\\rlap{Temperature}}} & \multicolumn{1}{c}{\rothead{\\ Date}} & \multicolumn{1}{c}{ \rothead{\\\rlap{Observations}}} & \multicolumn{1}{c}{\rothead{\rlap{TemperatureTest}\\ \rlap{on Hot Water}}} & \multicolumn{1}{c}{\rothead{\rlap{Temperature Test}\\\rlap{on Cold Water}}} & \multicolumn{1}{c}{\rothead{\\\rlap{Consistency}}} \\[-0.5ex]
    \hline
    \multirowcell{3}{Product \\ 1} & Company 1 & 13.5 & 84 & 1000.5 & \makecell{1000.7\\ 1000.8} & \\
    \cline{2-7} & Company 2 & 14.3 & 71 & 1000.2 & 1000.9 & 1000.12 \\
    \hline
  \end{tabular}}%

\end{document} 

enter image description here enter image description here

9
  • But is it possible to use these environments in a beamer document? I think I tried your code correctly and while beamer, for some reason, it does not work.
    – John Doe
    Commented Apr 8, 2015 at 18:22
  • I introduced it only because your table is too wide for a normal document. It also seems to be a little too wide for beamer. Perhaps use a smaller fontsize, or rotate column heads (there's a \rothead command in makecell)?
    – Bernard
    Commented Apr 8, 2015 at 18:33
  • So I would use \rothead instead of \thead then?
    – John Doe
    Commented Apr 8, 2015 at 20:18
  • As I said you have two solutions: reduce font size (which may be problematic for slides) or have rotated column heads. Or split into two tables, if it is sensible.
    – Bernard
    Commented Apr 8, 2015 at 20:23
  • @John Doe: I added a demo of what can be done with beamer and \rothead.
    – Bernard
    Commented Apr 8, 2015 at 21:04
1

I don't know what package \pbox comes from, but \parbox works just fine if you make it wide enough to contain "Temperature". OTOH, I couldn't get \bigstrut to do anything on the top row, so I used \fbox instead.

table

\documentclass{standalone}
\usepackage{multirow,bigstrut}
\begin{document}
\fboxrule=0pt
\centering
\begin{tabular}{|c|c|c|c|c|c|c|}
    \hline
    \textbf{Product} & \textbf{Temperature} & \textbf{Date} & \textbf{Observations} 
    & \fbox{\parbox{2.2cm}{\centering\textbf{Temperature Test on Hot Water}}}
    & \fbox{\parbox{2.2cm}{\centering\textbf{Temperature Test on Cold Water}}} & \textbf{Consistency} \\
    \hline
    \multirow{2}[4]{*}{\parbox{2cm}{\centering Product\\1}} & Company 1 & 13.5 & 84 & 1000.5 & 1000.7 1000.8 \bigstrut \\
    \cline{2-7}     & Company 2 & 14.3 & 71   & 1000.2 & 1000.9 & 1000.12 \bigstrut\\
    \hline
\end{tabular}%
\end{document

}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .