0

I'm working on a table in report documentclass. Here's some of my code below:

\documentclass[12pt]{report}

\usepackage[table]{xcolor} 

\setlength{\arrayrulewidth}{1mm}

\renewcommand{\arraystretch}{1.5} 


\begin{document}


\begin{table}
\begin{tabular}{l p{6cm} c m{3cm} r m{3cm}  }
\hline \\ 
 Country &   Parameter A & Parameter B  \\ [0.5ex]
\hline 

Quantity of x  &    0.8   & 25.6  \\ 

Quantity of y  &    100   & 9.4   \\  

Quantity of z  &    10    & 12.6   \\ 

Quantity of a  &  100   & 30    \\ 




\hline
\end{tabular}
\caption{Table 1}

\end{table}

\end{document}

My problem is that columns 2 and 3 are too wide apart. How can I get them to be a little closer together whilst giving more space to column 1 as I have more writing to do in column 1? I've read quite a lot of answers online and on this forum but I guess I'm missing something very fundamental here. I've played around a lot with \begin{tabular}{l p{6cm} c m{3cm} r m{3cm} } but all to no avail.

  • Welcome, do you mind updating your example code such that it compiles (makes it easier for others to work with, and makes it more likely to get help). You example is e.g. missing \begin/end{docuyment} – daleif Oct 8 '14 at 13:32
  • Why do you declare 6 columns and use 3? – Bernard Oct 8 '14 at 13:35
  • Somewhat related: tex.stackexchange.com/questions/183264/… and tex.stackexchange.com/questions/195899/… – user31729 Oct 8 '14 at 13:37
  • @Bernard-could you be more specific-I'm guessing this is probably where the problem is. Do you mean I should be writing something like \begin{tabular}{ p{6cm} p{3cm} p{3cm} }? – John_dydx Oct 8 '14 at 13:38
  • @John: I think, that was what Bernard meant. And did you consider the \tabcolsep length between the columns? – user31729 Oct 8 '14 at 13:39
1

As mentioned in comment, you have declared too many columns in your table. I deleted three of them. If you want to write long text in one column, you may use a p{width} column in order to control it to your needs.

Here is your table how I would recommend to type it:

% arara: pdflatex

\documentclass[12pt]{report}
\usepackage{lmodern}
\usepackage{microtype} % for better kerning in narrow columns
\usepackage{booktabs}
\usepackage{caption}
\usepackage{siunitx}

\begin{document}    
    \begin{table}
        \centering
        \begin{tabular}{p{3cm}S[table-format=3.1]S[table-format=2.1]} % adapt this 3cm to your needs
            \toprule 
            Country         & {Parameter A} & {Parameter B} \\
            \midrule            
            Quantity of $x$ & 0.8           & 25.6          \\          
            Quantity of $y$ & 100           & 9.4           \\              
            Quantity of $z$ & 10            & 12.6          \\                      
            Quantity of $a$ and some more writing if you like & 100 & 30 \\             
            \bottomrule
        \end{tabular}
        \caption{Table 1}       
    \end{table} 
\end{document}

enter image description here

I included the package microtype here in order to get a better kerning in narrow cells with long text. If you are having that much space, you could just adapt the width of the first column until it looks nice to you. If you are getting ugly results like in my screenshot or if you want all the "Quantity of..." aligned horizontally, you should make the last cell (or the first row) ragged right (thanks to Barbara Beeton for this objection).

This could look like \multicolumn{1}{>{\raggedright}p{3cm}}{Quantity of $a$ and some more writing if you like}, which yields:

enter image description here

  • I had the same idea. Finally, the second column would look better if simply centred, in my opinion. – Bernard Oct 8 '14 at 13:46
  • @Bernard Yes you are right for the single case, but maybe those were just dummy numbers. Don't know. I like to keep it consistent. At John: You may want to write 100.0 if you think that too dismembered or you omit all the siunitx beauty I am advocating here. – LaRiFaRi Oct 8 '14 at 13:50
  • 1
    the last entry in column 1 would really look better ragged right. – barbara beeton Oct 8 '14 at 13:51
  • @barbarabeeton sure. Will add that. Thanks. – LaRiFaRi Oct 8 '14 at 13:55
  • @LaRiFaRi, thanks so much for your answer. The numbers were just dummy numbers. – John_dydx Oct 8 '14 at 14:02

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.