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.

In addition to Right-centered columns in LyX, I have another problem, now with multicolumns. I want to center the number "98" (which spans two columns) above the two other columns. These shall be aligned "right-centered" with S[table-format=2.0]) and "nearer" to each other. See the code and image above.

\begin{table}[H]
\centering
\begin{threeparttable}
\caption{\textbf{\label{tab:ms-soziodemographische-parameter}blabla}}
\begin{tabular}{lS[table-format=2.0]S[math-rm=\mathit,table-format=2.1,input-symbols=()]cc}
\toprule 
 & \multicolumn{2}{>{\centering}p{0.2\columnwidth}}{\textbf{Pat. mit Kopfschmerzen}} &     \textbf{Pat. ohne Kopfschmerzen} & \textbf{p-Wert}\tabularnewline
\midrule
\midrule 
\textbf{Anzahl} & \multicolumn{2}{c}{98} & 82 & \textbf{\textit{0,001}}\tabularnewline
\midrule 
\textbf{Alter: Jahre (SD)} & 41 & (12,9) & 47,4 (12,6) &     \textbf{\textit{0,001}}\tabularnewline
\midrule 
\textbf{Geschlecht: n(\%)} &  &  &  & \textbf{\textit{0,001}}\tabularnewline
- Weiblich & 78 & (79,6) & 47 (57,3) & \tabularnewline
- Männlich & 20 & (20,4) & 35 (42,7) & \tabularnewline
\midrule 
\textbf{KD der MS: Jahre (SD)} & 11,2 & (8,6) & 13,7 (8,9) & 0,056\tabularnewline
\midrule 
\textbf{Verlaufsform: n(\%)} &  &  &  & \textbf{\textit{0,042}}\tabularnewline
- RRMS & 56 & (57,1) & 30 (36,6) & \tabularnewline
- SCP & 29 & (29,6) & 38 (46,3) & \tabularnewline
- PPMS & 11 & (11,2) & 13 (15,9) & \tabularnewline
- CIS & 2 & (2,0) & 1 (1,2) & \tabularnewline
\midrule 
\end{tabular}
\end{threeparttable}
\end{table}

Output looks like:

image.

share|improve this question
1  
Please state your exact question here as well (near the start). It is not OK to have to read another question in order to understand this one. –  Martin Scharrer Dec 20 '11 at 12:36
    
True. So my exact question is how to center the number "98" (which spans two columns) above the two columns. These shall be aligned "right-centered" with S[table-format=2.0]) and "nearer" to each other. –  Jan Dec 20 '11 at 12:47
    
Please edit your question to add this information. –  Martin Scharrer Dec 20 '11 at 12:48
1  
If you remove the table-format=x.y options, and add table-number-alignment=center to both S columns, does that give you what you're after? –  Torbjørn T. Dec 20 '11 at 13:25
    
It does. Thank you :-) –  Jan Dec 20 '11 at 13:56

2 Answers 2

up vote 2 down vote accepted

By adding table-number-alignment=center (left, right and the default center-decimal-marker are the other choices) in the column specification, and removing the table-format=x.y specifiers, the 98 is more centered above the columns.

(I don't exactly understand what's going on, as the table-format option should set table-number-alignment to center, according to the manual.)

enter image description here

\documentclass{article}
\usepackage{threeparttable}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{array}
\begin{document}
\begin{table}
\centering
\begin{threeparttable}
\caption{\textbf{\label{tab:ms-soziodemographische-parameter}blabla}}
\begin{tabular}{%
  l
  S[table-number-alignment=center]
  S[math-rm=\mathit,input-symbols=(),table-number-alignment=center]
  cc}
\toprule 
 & \multicolumn{2}{>{\centering}p{0.2\columnwidth}}{\textbf{Pat. mit Kopfschmerzen}} &     \textbf{Pat. ohne Kopfschmerzen} & \textbf{p-Wert}\tabularnewline
\midrule
\midrule 
\textbf{Anzahl} & \multicolumn{2}{c}{98} & 82 & \textbf{\textit{0,001}}\tabularnewline
\midrule 
\textbf{Alter: Jahre (SD)} & 41 & (12,9) & 47,4 (12,6) &     \textbf{\textit{0,001}}\tabularnewline
\midrule 
\textbf{Geschlecht: n(\%)} &  &  &  & \textbf{\textit{0,001}}\tabularnewline
- Weiblich & 78 & (79,6) & 47 (57,3) & \tabularnewline
- Männlich & 20 & (20,4) & 35 (42,7) & \tabularnewline
\midrule 
\textbf{KD der MS: Jahre (SD)} & 11,2 & (8,6) & 13,7 (8,9) & 0,056\tabularnewline
\midrule 
\textbf{Verlaufsform: n(\%)} &  &  &  & \textbf{\textit{0,042}}\tabularnewline
- RRMS & 56 & (57,1) & 30 (36,6) & \tabularnewline
- SCP & 29 & (29,6) & 38 (46,3) & \tabularnewline
- PPMS & 11 & (11,2) & 13 (15,9) & \tabularnewline
- CIS & 2 & (2,0) & 1 (1,2) & \tabularnewline
\midrule 
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}
share|improve this answer

Personally, I'd have to say that changing the alignment of the "98" item and the intercolumn width is less pressing than avoiding the current thorough mix-up of the contents of the columns: depending on the row, the column entries either denote years or sample sizes, and/or standard deviations and percentages. I assume that confusing your readers is not your objective. :-) I've tried to untangle the contents in the following MWE:

\documentclass{article}
\usepackage{lmodern}
\usepackage[ngerman]{babel}
\addto\extrasgerman{\sisetup{locale = {DE},table-format=2.1}
\usepackage{booktabs,float,siunitx,threeparttable}
\sisetup{locale=DE}
\begin{document}
\begin{table}[H]
\centering
\begin{threeparttable}
\caption{blabla}
\label{tab:ms-soziodemographische-parameter}
\begin{tabular}{l *{2}{S S[math-rm=\mathit]} r}
\toprule 
 & \multicolumn{2}{>\centering p{0.18\columnwidth}}{\textbf{Pat. mit Kopfschmerzen}} 
 & \multicolumn{2}{>\centering p{0.18\columnwidth}}{\textbf{Pat. ohne Kopfschmerzen}} 
 & \textbf{p-Wert}\\
\midrule
 & \multicolumn{1}{c}{Jahre}
 & \multicolumn{1}{c}{\textit{SD}}
 & \multicolumn{1}{c}{Jahre}
 & \multicolumn{1}{c}{\textit{SD}} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} 
\textbf{Alter} & 41 & 12,9 & 47,4 & 12,6 & 0,001\\
\textbf{KD der MS} & 11,2 & 8,6 & 13,7 & 8,9 & 0,056\\[1ex]
\midrule
 & \multicolumn{1}{l}{ n}
 & \multicolumn{1}{c}{\textit{\%}}
 & \multicolumn{1}{l}{ n}
 & \multicolumn{1}{c}{\textit{\%}} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} 
\textbf{Anzahl} & 98 & & 82 & & 0,001\\[1ex]
\textbf{Geschlecht} &  &  &  & & 0,001\\[0.25ex]
- Weiblich & 78 & 79,6 & 47 & 57,3 & \\
- M\"annlich & 20 & 20,4 & 35 & 42,7 & \\[1ex]
\textbf{Verlaufsform} &  &  &  & & 0,042\\[0.25ex]
- RRMS & 56 & 57,1 & 30 & 36,6 & \\
- SCP & 29 & 29,6 & 38 & 46,3 & \\
- PPMS & 11 & 11,2 & 13 & 15,9 & \\
- CIS & 2 & 2,0 & 1 & 1,2 & \\
\midrule 
\end{tabular}
\end{threeparttable}
\end{table}
\end{document}

enter image description here

share|improve this answer
    
I know that it can be misleading. However my supervisor wants it exactly this way and I'm not going to argue with him (at least on this topic...). –  Jan Dec 20 '11 at 19:19
    
Aaah yes, the supervisor's dreaded requirements... Just keep your head low and try to get out from under his shadow as quickly as you can. :-) –  Mico Dec 20 '11 at 21:26

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.