1

I have looked at previous queries of similar issues but the solutions don't seem to work for me (I am very new to LaTex so this is probably just me!)

I am making a table which I want to fit within the page width of my document. I have tried tabularx and tabulary (using \textwidth or \linewidth)but this seems to only make the lines of the table the correct width with the text still running off. Any solutions will be great!

This is the current code with no formatting trying to fix the width issue:

\documentclass{article}

\begin{document}
This is a line of text to show the line width to ensure the table is the correct width on the page
\begin{center}
\begin{tabular}{c|c|c|c|c}
\hline
\multicolumn{4}{c}{Error in Gilson Autopipettes} \\
\hline
Autopipette & Max. Volume ($\mu$ L) & Sytematic Error ($\mu$ L) & Random Error ($\mu$ L) & Max. Error ($\mu$ L) \\
\hline
P10 & 10 & $\pm$ 0.100 & $\leq$ 0.040 &  \\
P200 & 200 & $\pm$ 1.60 & $\leq$ 0.30 &  \\
P1000 & 1000 & $\pm$ 8 & $\leq$ 1.5 &  \\
\hline
\end{tabular}
\end{center}
\end{document}
1
  • Did you use X columns in combination with tabularx or C cells in combination with tabulary? The width of these sorts of columns is calculated in a way that the table fits the specified width and content is automatically wrapped.
    – leandriis
    Commented Oct 7, 2017 at 16:17

1 Answer 1

1

like this?

enter image description here

  • for tabularx you can prescribe table width, however, than you need to use at least one column type X (or derivative from it) in table. otherwise, table will have width of cell contents
  • for writing numbers in columns i suggest to use S columns from siunitx package. using it the numbers are aligned at decimal point or right side, if numbers are intefgers
  • for units also use siunitx package (see mwe below)
  • for writing
  • for professional looking of table don't use vertical lines, for horisontal use rules defined by booktabs package
  • added package lipsum is for dummy text, in real document you should remove it, the same is valid for showframe, which purpose is show page layout (red lines on above image.

\documentclass{article}
\usepackage{booktabs, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcommand\mcx[1]{\multicolumn{1}{C}{#1}}
\usepackage{siunitx}

\usepackage{lipsum}
%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%


\begin{document}
\lipsum[11]
\begin{center}
\begin{tabularx}{\linewidth}{X S >{\pm}S >{\pm}S S}
    \toprule
    &   \multicolumn{4}{c}{Error in Gilson Autopipettes}    \\
    \cmidrule(lr){2-5}
\mcx{Autopipette}
    &   \mcx{Max. Volume (\si{\micro\liter})}
        &   \mcx{Sytematic Error (\si{\micro\liter})}
            &   \mcx{Random Error (\si{\micro\liter})}
                &   \mcx{Max. Error (\si{\micro\liter})}    \\
    \midrule
P10     &   10      &   0.100   &   0.040  &                \\
P200    &   200     &   1.60    &   0.30   &                \\
P1000   &   1000    &   8       &   1.5    &                \\
    \bottomrule
\end{tabularx}
\end{center}
\end{document}

edit:

for shorter code you can define new commands, similarly as it is defined for \multicolumn in above mwe, for units \micro\liter (as suggested Bernard in his comment below:

in preamble, after \usepackage{siunitx}: \newcomand{\ul}{\micro\liter}

and use in table:

\mcx{Autopipette}
    &   \mcx{Max. Volume (\si{\uL})}
        &   \mcx{Sytematic Error (\si{\uL})}
            &   \mcx{Random Error (\si{\uL})}
                &   \mcx{Max. Error (\si{\uL})}    \\
3
  • I suggest slightly shorten the code, using the abbreviation \uL in the place of \micro\liter.
    – Bernard
    Commented Oct 7, 2017 at 16:29
  • good idea :-), i will add this to answer asap! thank you
    – Zarko
    Commented Oct 7, 2017 at 16:36
  • Thank you so much! Slowly getting my head around all of this, your help is invaluable:)
    – KirstyA
    Commented Oct 7, 2017 at 16:58

You must log in to answer this question.

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