0

Given the following table, I would like to add a further column:

\begin{table}[H]
\begin{tabularx}{\textwidth}{|X|l|}
\hline

Total number of atoms & 426 \\
Number of electrons & 260 \\

\hline
\end{tabularx}
\caption{test }
\label{t:stats}
\end{table}

I assumed it would be something like:

\begin{table}[H]
\begin{tabularx}{\textwidth}{|X|l|}
\hline

Total number of atoms & 426 & 520 \\
Number of electrons & 260 & 118 \\

\hline
\end{tabularx}
\caption{test }
\label{t:stats}
\end{table}

..but this does not work. Thanks

  • 3
    \begin{tabularx}{\textwidth}{|X|l|l|}. But why the X column? Just to make reading difficult? – egreg Mar 5 '18 at 18:28
  • Did not know that it makes reading more difficult - how so? – Pegah Mar 5 '18 at 18:40
  • 1
    It moves the data far from their description. So, unless typesetting in double column, I'd not do it. – egreg Mar 5 '18 at 18:46
1

That's because most tabular-and-friends require you to update the column specification as well:

\begin{tabular}{<col spec>}
  % <your table here>
\end{tabular}

or

\begin{tabularx}{<width>}{<col spec>}
  % <your table here>
\end{tabularx}

So, for adding another column to the right within your tabularx from

\begin{tabularx}{<width>}{ | X | l | }
  % <your table here>
\end{tabularx}

you would need (say)

\begin{tabularx}{<width>}{ | X | l | r | }
  % <your table here>
\end{tabularx}

Here r/l/c/p{<len>} denotes a right/left/centre-aligned column, while p{<len>} fits a paragraph of width <len>. Other options are also available, depending on the packages you're loading.

  • Many thanks, quick question: In this setting, how can I add a line below the first row (e.g. to have there the titles)? – Pegah Mar 5 '18 at 18:45
  • 1
    @Pegah: First, using tabularx puts the table as wide as <width>. If your row-wise content falls far short of <width>, it's better to just use a regular tabular (without a <width> specification). Second, here is how I'd post your table, using booktabs and without tabularx. – Werner Mar 5 '18 at 18:52

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.