Graphics, Figures & Tablessiunitx and fixed-width columns in tabular

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

siunitx and fixed-width columns in tabular

Post by cbkschroeder »

Hello,

Is there a way to make fixed-width columns --- of a specific numeric length --- when using siunitx?

The following code produces an acceptable table:

Code: Select all

\documentclass{article}

\usepackage{booktabs}
\usepackage{array}

\begin{document}

\newcolumntype{C}[1]{>{\centering}m{#1}}

\begin{table}
    \centering
    \begin{tabular}{C{1in}C{1in}C{1in}C{1in}} \toprule
    \mbox{Row Address/} State Vector & $G_x$~value &  $G_y$~value &  $G_z$~value \tabularnewline \midrule
    0 & 0 & 0 & 0 \tabularnewline
    1 & 0 & 0 & +8192 \tabularnewline
    2 & 0 & 0 & -16384 \tabularnewline
    3 & 0 & 0 & 0 \tabularnewline
    4 & 0 & 0 & +4096 \tabularnewline
    5 & +6144 & 0 & +4096 \tabularnewline
    6 & 0 & 0 & +4096 \tabularnewline \bottomrule
\end{tabular}
\end{table}%

\end{document}
The output can be seen here:
mwe.pdf
(31.37 KiB) Downloaded 410 times
Each column is a nice, equal 1 inch in width, and all content is middle-centered in each specific cell. Unfortunately, if I want to now access siunitx's/my document's standard numeric formatting, I'm forced to put

Code: Select all

\num{}
around each of my entries. I'd like to avoid this.

Does anyone know if it is possible to make siunitx (and its standard "S" column type) make a fixed-width column? I'd love your ideas.

Thanks for your time.

Recommended reading 2024:

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

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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

siunitx and fixed-width columns in tabular

Post by localghost »

I think bringing an example where everything works fine is the wrong approach to the problem. If you want a table that works with siunitx, incorporate it and show occurring problems with an appropriate example. The package manual should be the best source of information about what's possible and what's not.


Thorsten
josephwright
Site Moderator
Posts: 814
Joined: Tue Jul 01, 2008 2:19 pm

siunitx and fixed-width columns in tabular

Post by josephwright »

I can't see how you can fix the column width, as the content needs to be able to grow/shrink to keep the alignment. However, you can fix the width of the widest entry:

Code: Select all

\documentclass{article}
\usepackage{siunitx}
\begin{document}
  \begin{tabular}{SSS}
  {\parbox{1in}{\centering Text here}} &
  {\parbox{1in}{\centering Text here}} &
  {\parbox{1in}{\centering Text here}} \\
  1.2  & 1.2  & 1.2  \\
  3.45 & 3.45 & 3.45 \\
  3.45 & 3.45 & 3.45 \\
  \end{tabular}
\end{document}
which I assume achieves the effect you want. If not, please post an example showing the issue in more detail.
Joseph Wright
cbkschroeder
Posts: 55
Joined: Sun Nov 09, 2008 7:48 pm

Re: siunitx and fixed-width columns in tabular

Post by cbkschroeder »

Joseph,

Thank you for your response; yes, your suggestion does do what I wish. I appreciate that you wrote.

I understand the need for free-moving columns, particularly in the way siunitx has been implemented, however, would you ever consider something like a "p" column type where one can specify a fixed, hard width? If it's two small, LaTeX would give an error, or course. At this point it's simply a thought that I had since I had one circumstance where it might have been useful. I'm sure you have vastly more insight into this than I!

Thorsten: you're right, I enacted an unusual approach to presenting my problem. I felt, however, that it did say best what I wanted to say. In general, however, I agree wholeheartedly with what you've said. The documentation for a package can sometimes, though, merely represent the starting point of a search!

As always, I appreciate both your responses. Take care.
Post Reply