3

I've been fiddling with a table layout where some cells contain very little text while others may need multiple lines, and I can't seem to get it readable and nice-looking.

MWE:

\documentclass{article}
\usepackage{booktabs}
\usepackage{array}
\usepackage{rotating}

\begin{document}

\rotatebox{90}{
\begin{tabular}{l@{\hspace{1em}}>{\raggedright}p{.2\textheight}>{\raggedright}p{.2\textheight}>{\raggedright}p{.2\textheight}>{\raggedright\arraybackslash}p{.2\textheight}}
\toprule
\multicolumn{2}{l}{heading 1} & heading 2 & heading 4 & heading 4 \\
\midrule
\multicolumn{2}{l}{sub-heading} &       &       &  \\
\cmidrule(lr){1-5}      & long long long long long long long long long long long long text & a & b  & c \\
      & x & long long long long long long long long long text & long long long long long long long long long text & y \\
      & short & short & short & short \\
      & x & y & z & long long long long long long long long long text \\
\bottomrule
\end{tabular}
}
\end{document}

The output is hardly readable, especially for the third line (short/short/short/short), it is nearly impossible to distinguish whether its elements are one line in the table or part of the (depending on the column) previous/next line. I've played around with \arraystretch, but then the header lines had too much spacing and the readability was not really increased.

5

Not a problem yet as your entries are smaller than textheight but you have a word space to either side of the table due to missing %

here

\rotatebox{90}{%

and here

\end{tabular}%

It seems to be intentional but I think the first heading looks odd offset 1em to the left as all the other headings are flush left with their respective cells.

Probably you need some visual distinction of the rows, either increasing the separation, or adding cmidline or adding colour..

enter image description here

\documentclass{article}
\usepackage{booktabs}
\usepackage{graphicx}
\usepackage{colortbl}

\begin{document}

\rotatebox{90}{%
\setlength\extrarowheight{5pt}
\begin{tabular}{@{}>{\raggedright}p{.2\textheight}>{\raggedright}p{.2\textheight}>{\raggedright}p{.2\textheight}>{\raggedright\arraybackslash}p{.2\textheight}@{}}
\toprule
heading 1 & heading 2 & heading 4 & heading 4 \\
\midrule
sub-heading &       &       &  \\
\cmidrule(lr){1-4}  long long long long long long long long long long long long text & a & b  & c \\[3pt]
       x & long long long long long long long long long text & long long long long long long long long long text & y \\
       short & short & short & short \\
       x & y & z & long long long long long long long long long text \\
\bottomrule
\end{tabular}%
}

\rotatebox{90}{%
\setlength\extrarowheight{2pt}
\begin{tabular}{@{}>{\raggedright}p{.2\textheight}>{\raggedright}p{.2\textheight}>{\raggedright}p{.2\textheight}>{\raggedright\arraybackslash}p{.2\textheight}@{}}
\toprule
heading 1 & heading 2 & heading 4 & heading 4 \\
\midrule
sub-heading &       &       &  \\
\cmidrule(lr){1-4}  long long long long long long long long long long long long text & a & b  & c \\[3pt]
\rowcolor[rgb]{.9,.9,.9}
       x & long long long long long long long long long text & long long long long long long long long long text & y \\
       short & short & short & short \\
\rowcolor[rgb]{.9,.9,.9} 
       x & y & z & long long long long long long long long long text \\
\bottomrule
\end{tabular}%
}


\end{document}
  • Thanks! The offset of the first heading is intentional to make the table look consistent with others in my document where the indentation is more meaningful ;). – rainer May 16 '13 at 13:12
2

use a tabularx:

\documentclass{article}
\usepackage{tabularx,booktabs}
\usepackage{graphicx,ragged2e}
\usepackage[table]{xcolor}
\renewcommand\tabularxcolumn[1]{>{\RaggedRight}p{#1}}
\begin{document}

\noindent
{\setlength\extrarowheight{5pt}
\begin{tabularx}{\textwidth}{@{} *5X @{}}\toprule
heading 1 & heading 2 & heading 4 & heading 4 \\\midrule
sub-heading &       &       &  \\\cmidrule(lr){1-4}  
 long long long long long long long long long long long long text & a & b  & c \\[3pt]
  x & long long long long long long long long long text & long long long long long long long long long text & y \\
 short & short & short & short \\
  x & y & z & long long long long long long long long long text \\\bottomrule
\end{tabularx}}

\rotatebox{90}{%
\setlength\extrarowheight{2pt}
\begin{tabularx}{0.95\textheight}{ *5X }\toprule
heading 1 & heading 2 & heading 4 & heading 4 \\\midrule
 sub-heading &       &       &  \\\cmidrule(lr){1-4}  
 long long long long long long long long long long long long text & a & b  & c \\[3pt]
\rowcolor{black!10}
       x & long long long long long long long long long text & long long long long long long long long long text & y \\
       short & short & short & short \\
\rowcolor{black!10} 
       x & y & z & long long long long long long long long long text \\\bottomrule
\end{tabularx}%
}

\end{document}

enter image description hereenter image description here

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.