Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

latex padding / margin hell

I have been wrestling with a latex table for far too long. I need a table that has has centered headers, and body cells that contain text that may wrap around. Because of the wrap-around requirement, i'm using p{xxx} instead of l for specifying cell widths. The problem this causes is that cell contents are not left justified, so the look like spaced-out junk. To fix this problem I'm using \flushleft for each cell. This does left justify contents, but puts in a ton of white space above and below the contents of the cell. Is there a way to stop \flushleft (or \center for that matter) to stop adding copious amounts of verical whitespace?

thanks

\begin{landscape}
    \centering
    % using p{xxx} here to wrap long text instead of overflowing it
    \begin{longtable}{ | p{4cm} || p{3cm} | p{3cm} | p{3cm} | p{3cm} | p{3cm} |}
        \hline
         & 
        % these are table headings.  the \center is causing a ton of whitespace as well
        \begin{center} \textbf{HTC HD2} \end{center} & 
        \begin{center} \textbf{Motorola Milestone} \end{center} & 
        \begin{center} \textbf{Nokia N900} \end{center} & 
        \begin{center} \textbf{RIM Blackberry Bold 9700} \end{center} &
        \begin{center} \textbf{Apple iPhone 3GS} \end{center} \\
        \hline
        \hline
        % using flushleft here to left-justify, but again it is causing a ton of white space above and below cell contents.
        \begin{flushleft}OS / Platform \end{flushleft}& 
        \begin{flushleft}Windows Mobile 6.5 \end{flushleft}& 
        \begin{flushleft}Google Android 2.1 \end{flushleft}& 
        \begin{flushleft}Maemo \end{flushleft}& 
        \begin{flushleft}Blackberry OS 5.0 \end{flushleft}& 
        \begin{flushleft}iPhone OS 3.1 \end{flushleft} \\           
        \hline

Edit:

Thanks for the answers so far. I thought I found a solution that works, but these problems still exist:

  • using \raggedright stops long words from being hyphenated. This looks pretty bad when a cell contains a bunch of lines with only one word in them.
  • using \raggedright only works if you end it with a blank line. This causes every cell to have a completely blank line at the bottom of it. This was what i was trying to avoid in the first place.

        {Display} & 
        {\raggedright 4.3 inch, 800 x 400 resolution} & 
        {\raggedright 3.7 inch, 854 x 480 resolution} & 
        {\raggedright 3.5 inch, 800 x 480 resolution} & 
        {\raggedright 2.44 inch, 320 x 480 resolution} & 
        {\raggedright 3.5 inch, 480 x 320 resolution} \\            
        \hline
    
like image 590
D.C. Avatar asked Nov 14 '25 13:11

D.C.


1 Answers

You should be fine to just specify how you want the body cells formated and change only the headers to centered with multicolumn. That way you don't have to mess with too many cells like you do right now.

\documentclass{article}

\begin{document}
\begin{table}
  \centering
  \begin{tabular}{l|p{2cm}|p{2cm}}
    \multicolumn{1}{c}{A} &
    \multicolumn{1}{c}{B} &
    \multicolumn{1}{c}{C} \\
    1 & {Some longer text} & {Some other text}\\
    2 & {Some longer text} & {Some other text}\\
    3 & {Some longer text} & {Some other text}\\
    4 & {Some longer text} & {Some other text}
  \end{tabular}
\end{table}
\end{document}
like image 127
Benjamin Bannier Avatar answered Nov 17 '25 07:11

Benjamin Bannier