Graphics, Figures & TablesText fit with column widths

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
philalou
Posts: 6
Joined: Sat Nov 29, 2014 10:04 pm

Text fit with column widths

Post by philalou »

Hi all,

First I am still discovering the large possibilities of LaTeX and am very excited of using it for compiling my thesis.

I'm struggling however at compiling tables. Find bellow the code of a table I'm currently trying of adding to my document.

Code: Select all

\begin{table}
\begin{tabulary}{1\textwidth}{CCCCCCCCC}
    ~ & Slope of the electrode response (mV/decade) & Detection Limit (log a$_{Mg2+}$) & Dynamic range (log a$_{Mg2+}$) & \multicolumn{3}{C}{Selectivity coefficients (log K$_{Mg,X}^{Pot}$)} & Response time(t$_{95}$\%, s) & Membrane ohmic resistance (G$\Omega$) \\ \hline
~ & ~ & ~ & ~ & X = Na$^{+}$ & X = Ca$^{2+}$ & X = OH$^{-}$ & ~ & ~ \\ \hline
Values & 23 \pm 1 (n = 20) & -5.8 \pm 0.2 (n = 20) & -5.7 to -1.4 & -4.0 \pm 0.4 (n=3) & -0.3 \pm 0.8 (n=3) & -12.9 \pm 0.9 (n=3) & 1.7 \pm 0.3 (n = 6) & 20 \pm 5 (n = 6) \\
\end{tabulary}
\caption{Micro-Mg$^{2+}$ sensor potentiometric properties. Figures of merit are all expressed at a 95\% confidence interval.}
\label{tab:Table3-1}
\end{table}
The issue with it is that it appears that the text gets all squeezed up in the first row, especially the 5th column.

Any idea, how I can solve this issue?

Thanks a lot for all the help, it is very appreciated.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Text fit with column widths

Post by Johannes_B »

Hi and welcome,

tabulary and the C column specifier aren't basic latex. Can you extend the code to give us just the stuff we need to compile this table? It is also called a minimal working example.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
philalou
Posts: 6
Joined: Sat Nov 29, 2014 10:04 pm

Text fit with column widths

Post by philalou »

Hi Johannes_B,
Thank you for your answer. I have breeze quickly through the minimal working example document you posted. I think with the new code I'm posting, this answers your demand.

Code: Select all

\documentclass[12pt]{report}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{tabulary}

\begin{document}

\begin{table}
    \begin{tabular}{ccccccccc}
    ~      & Slope of the electrode response & Detection Limit & Dynamic range & \multicolumn{3}{c}{Selectivity coefficients} & Response time & Membrane ohmic resistance \\
    ~      & (mV/decade) & (log a$_{Mg^{2+}}$) & (log a$_{Mg^{2+}}$) & \multicolumn{3}{c}{(log K$_{Mg,X}^{Pot}$)} & (t$_{95}$\%, s) & (G$\Omega$)\\ 
    \hline
    ~ & ~ & ~ & ~ & X = Na$^{+}$ & X = Ca$^{2+}$ & X = OH$^{-}$ & ~ & ~ \\ \hline
    Values & 23 \pm 1 & -5.8 \pm 0.2 & -5.7 to -1.4 & -4.0 \pm 0.4 & -0.3 \pm 0.8 & -12.9 \pm 0.9 & 1.7 \pm 0.3 & 20 \pm 5 \\
     ~ & (n = 20) & (n = 20) & ~ & (n=3) & (n=3) & (n=3) & (n = 6) & (n = 6) \\
    \end{tabular}
\end{table}

\end{document}
As you should notice, the table is getting off margins. Is there a way LaTeX approach for fitting the content of each column so in the end it fits the document?
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Text fit with column widths

Post by Johannes_B »

This example is much better, there is still some inline math missing. I guess it was in your initial column specifier.

The table as it is right now is too wide (even for a landscape page), you noticed that yourself. One way to make it fit a bit better would be making the font size smaller, which is a very bad idea (inconsistent).
Usually, a table lists data of different sets. Do you have just the one? Why don't you just transpose the tabular, making the columns to rows and vice versa. Splitting the first/second column (Slope of the electrode response) and the very last one in two lines might gain a little bit.

Btw, did you notice that an atom in you subscripts is typeset in italics while it is upright in normal text? This is inconsistent, be careful. An easy way to write down chemistry (in a very consistent way) is using package chemformula (along with many packages of the same author). The same goes for units of the SI system for which package siunitx is available. Both package authors are moderators here at LaTeX-Community.

If you give a bit more details on the contents, i am sure we will find a nice solution. Unfortunately, my chemistry is a bit rusty.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
philalou
Posts: 6
Joined: Sat Nov 29, 2014 10:04 pm

Re: Text fit with column widths

Post by philalou »

Thank you Johannes for your suggestions.

I ended up transposing my table.
Post Reply