Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This is very near to my topic: How to align integers on the right, but still center them. However, I do not get it to work under LyX. This is the code I have:

\begin{table}[H]
\centering
\begin{threeparttable}\caption{\textbf{\label{tab:uebersicht-alle-mspatienten}Untersuchungsergebnisse der soziodemographischen und neurologischen Parameter aller untersuchten MS-Patienten} }
\begin{tabular}{>{\raggedright}p{0.35\columnwidth}>{\centering}p{0.1\columnwidth}>{\centering}p{0.1\columnwidth}>{\centering}p{0.1\columnwidth}>{\centering}p{0.1\columnwidth}}
\toprule 
 & \textbf{Anzahl (n)} & \textbf{Prozent} & \textbf{Mittelwert} & \textbf{SD}\tabularnewline
\midrule
\midrule 
\textbf{Patienten} & 180 &  &  & \tabularnewline
\midrule 
\textbf{Alter} (in Jahren) &  &  & 43,9 & 13,1\tabularnewline
\midrule 
\textbf{Geschlecht:}
- Weiblich
- Männlich & ~
125
55 & ~
69,4
30,6 &  & \tabularnewline
\midrule 
\textbf{Erkrankungsdauer der MS}
(in Jahren) &  &  & 12,3 & 8,8\tabularnewline
\midrule 
\textbf{Verlaufsform:}
- RRMS
- SCP
- PPMS
- CIS & ~
86
67
24
3 & ~
47,8
37,2
13,3
1,7  &  & \tabularnewline
\midrule 
\end{tabular}
\end{threeparttable}
\end{table}

It produces the following (correct) output:

However, if I change the first line to:

\begin{tabular}{>{\raggedright}p{0.35\columnwidth}S[table-format=3.0]>{\centering}p{0.1\columnwidth}>{\centering}p{0.1\columnwidth}>{\centering}p{0.1\columnwidth}}

it gives the following (incorrect) output:

My version of siunitx is 2.2i (2011/06/15) from TeX Live 2011.

share|improve this question
1  
You need to remove the braces (grouping) around your S[table-format=3.0] column definition. –  Werner Dec 19 '11 at 22:07
    
Like so? Then I get even more errors (all illegal pream-token): \begin{tabular}{>{\raggedright}p{0.35\columnwidth}S[table-format=3.0]>{\centerin‌​g}p{0.1\columnwidth}>{\centering}p{0.1\columnwidth}>{\centering}p{0.1\columnwidth‌​}} –  Jan Dec 19 '11 at 22:11
    
Sorry, I had commented out the usepackage command, now the doc. compiles fine. –  Jan Dec 19 '11 at 22:15
1  
Yes. Did you include the siunitx package? If so, what version do you have (add \listfiles before \documentclass and view the contents of your .log file after **File List**)? The most recent version on CTAN is 2011/12/11 v2.4e. –  Werner Dec 19 '11 at 22:15
    
For completeness, since it seemed to have solved your problem, I've converted my comment into an answer. –  Werner Dec 19 '11 at 22:21
add comment

1 Answer

up vote 3 down vote accepted

The elements contained within the column specification of a tabular environment should be considered similar to single-letter commands that may take parameters. For example, S[<key-value list>] denotes an S column with parameters set according to the (optional) <key-value list>. Wrapping this in braces

\begin{tabular}{...{S[table-format=3.0]}...}

confuses LaTeX. Removing the braces should fix your problem:

\begin{tabular}{...S[table-format=3.0]...}

Also remember to include the siunitx package, since it defines the S column type.


Here is a minimal example of your input producing the correct layout when using siunitx:

enter image description here

\documentclass{article}
\usepackage{siunitx}% http://ctan.org/pkg/siunitx
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{threeparttable}% http://ctan.org/pkg/threeparttable
\begin{document}
\begin{table}[H]
  \centering
  \begin{threeparttable}
    \caption{\textbf{\label{tab:uebersicht-alle-mspatienten}Untersuchungsergebnisse der soziodemographischen 
      und neurologischen Parameter aller untersuchten MS-Patienten}}
%    \begin{tabular}{>{\raggedright}p{0.35\columnwidth}
%        >{\centering}p{0.1\columnwidth}
%        >{\centering}p{0.1\columnwidth}
%        >{\centering}p{0.1\columnwidth}
%        >{\centering}p{0.1\columnwidth}}
    \begin{tabular}{>{\raggedright}p{0.35\columnwidth}
        S[table-format=3.0]
        >{\centering}p{0.1\columnwidth}
        >{\centering}p{0.1\columnwidth}
        >{\centering}p{0.1\columnwidth}}
      \toprule 
      & \textbf{Anzahl (n)} & \textbf{Prozent} & \textbf{Mittelwert} & \textbf{SD}\tabularnewline
      \midrule
      \midrule 
      \textbf{Patienten} & 180 &  &  & \tabularnewline
      \midrule 
      \textbf{Alter} (in Jahren) &  &  & 43,9 & 13,1\tabularnewline
      \midrule 
      \textbf{Geschlecht:} \tabularnewline
      - Weiblich & 125 & 69,4 & & \tabularnewline
      - M\"{a}nnlich & 55 & 30,6 &  & \tabularnewline
      \midrule
      \textbf{Erkrankungsdauer der MS}
      (in Jahren) &  &  & 12,3 & 8,8 \tabularnewline
      \midrule
      \textbf{Verlaufsform:} \tabularnewline
      - RRMS & 86 & 47,8 \tabularnewline
      - SCP & 67 & 37,2 \tabularnewline
      - PPMS & 24 & 13,3 \tabularnewline
      - CIS & 3 & 1,7 &  & \tabularnewline
      \midrule 
    \end{tabular}
  \end{threeparttable}
\end{table}
\end{document}

TeX constructs a table (tabular) on a row-by-row basis. It seems like your code (at least what is given in your code snippet) doesn't allow for this row-by-row construction. Specifically, as an example,

\textbf{Verlaufsform:}
- RRMS
- SCP
- PPMS
- CIS & ~
86
67
24
3 & ~
47,8
37,2
13,3
1,7  &  & \tabularnewline

needs to be modified to read

\textbf{Verlaufsform:} \tabularnewline
- RRMS & 86 & 47,8 \tabularnewline
- SCP & 67 & 37,2 \tabularnewline
- PPMS & 24 & 13,3 \tabularnewline
- CIS & 3 & 1,7 &  & \tabularnewline

otherwise all the entries that seems like it should be processed in the same column (underneath one another) will end up in the same column on a single row. TeX's output will not match your code layout as input - you need to explicitly say where the columns are separated (using &), just like you explicitly state where the row ends (using \\ or \tabularnewline).

share|improve this answer
    
Unfortunately, it now looks like !this instead of !this Is there sth. I'm missing ? –  Jan Dec 19 '11 at 22:28
1  
@Jan: Please add the entire code you have that generates the output you included to your original post via an edit, as well as the images. As a new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. Someone with editing privileges will embed the link for you. That way we can assess what the problem is. Also include your version of the siunitx package. –  Werner Dec 19 '11 at 22:30
1  
Although I know to say thank you by clicking the arrow, I wanted to do it the old way ;-) Btw Lyx produced this code. I inserted another lines (like you suggested) and now it works. –  Jan Dec 19 '11 at 23:23
    
@Jan: You're welcome! I think LyX sometimes removes the intricacies of (La)TeX coding from the inexperienced user in order to make a little more WYSIWYM (or WYSIWYG). However, this can obscure problems. –  Werner Dec 19 '11 at 23:51
    
@Jan: How did you do this in LyX? Did you write the whole table in a raw block, or is it possible to somehow use the table editor in combination with the siunitx package's S column type? –  andreas-h Apr 11 '13 at 15:42
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.