2

I have made a table with 5 columns, of which I'd like the last 4 to be of the same width. Therefore I was told I should use tabluarx. Using this package my output looks fine, but I have also numbers inside the last 4 columns, mixed with %-values. I'd like to adjust to the decimal point first PLUS then make the columns of equal width. Is this possible with any package out there? If not, can some1 show me the solution to only align to the decimal point? I wasn't able to solve it using siunitx, because I have also text inside my table (first column mainly).

Thanks for any help. Here is the MWE:

\documentclass[a4paper, 12pt]{scrreprt}
\usepackage{setspace}
\usepackage{booktabs}
\usepackage{floatrow}
\floatsetup[table]{capposition=top}
\usepackage{tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}

\begin{table}[htpb]
\begin{tabularx}{0.85\textwidth}{lYcYcYcYcY}
    \toprule
    \multicolumn{1}{l}{Test 1} & \multicolumn{2}{c}{Test 2} & \multicolumn{2}{c}{Test 3} \\
    Observations successfull & no & yes  & maybe & no  \\
    adsadad & 546546.546 & 45.646 & 45.646 & 456.456 \\
    \% AAA & 235.25\% & 2525\% & 2342.34\% & 234.2525\% \\
    \% BBB & 0.0029 & N/A & 0.0031 & N/A \\
    \% CCC & 0.0033 & N/A & 0.0031 & N/A \\
    \bottomrule

\end{tabularx}
\end{table}

\end{document}

Let me know.

6

enter image description here

\documentclass[a4paper, 12pt]{scrreprt}
\usepackage{setspace}
\usepackage{booktabs}
\usepackage{floatrow}
\floatsetup[table]{capposition=top}
\usepackage{dcolumn}
\newcolumntype{Y}{D..{6.4}}

\begin{document}

\begin{table}[htpb]
\begin{tabular}{lYYYY}
    \toprule
    \multicolumn{1}{l}{Test 1} & \multicolumn{2}{c}{Test 2} & \multicolumn{2}{c}{Test 3} \\
    Observations successful &
\multicolumn{1}{c}{no} & 
\multicolumn{1}{c}{yes}  &
\multicolumn{1}{c}{maybe} &
\multicolumn{1}{c}{no}  \\
    adsadad & 546546.546 & 45.646 & 45.646 & 456.456 \\
    \% AAA & 235.25\% & 2525\% & 2342.34\% & 234.2525\% \\
    \% BBB & 0.0029 & \multicolumn{1}{c}{N/A} & 0.0031 & \multicolumn{1}{c}{N/A} \\
    \% CCC & 0.0033 & \multicolumn{1}{c}{N/A} & 0.0031 & \multicolumn{1}{c}{N/A} \\
    \bottomrule

\end{tabular}
\end{table}

\end{document}
2

This approach is a complete alternative, using the in-progress tabstackengine package found at Writing a table with equally spaced columns, based on the widest column. In fact the \kern in my solution is because there is still some sort of spacing issue that I need to locate and eliminate.

But I thank you for giving me the chance to test the package on real problems. I've confirmed that uncommenting the eliminated packages below does not affect the result.

\documentclass[a4paper, 12pt]{scrreprt}
%\usepackage{setspace}
%\usepackage{booktabs}
%\usepackage{floatrow}
%\floatsetup[table]{capposition=top}
%\usepackage{tabularx}
\usepackage{tabstackengine}
\strutlongstacks{T}
\begin{document}
\setbox0=\hbox{\alignLongstack{
&Test1 &&\rlap{~~~Test2}&&&&\rlap{~~~Tests3}&&&\\
&Observations successful & no&   & ye&s    & may&be & no&\\
& adsadad& 546546.&546 & 45.&646 & 45.&646   & 456.&456\\
&\% AAA  & 235.&25\%   & 2525&\% & 2342.&34\% & 234.&2525\%\\
&\% BBB  & 0.&0029     &     N/&A  & 0.&0031 & N/&A\\
&\% CCC  & 0.&0033     &     N/&A  & 0.&0031 & N/&A   
}}
\begin{tabular}{c}
\hline
\box0\kern-1.5\tabcolsep\\
\hline
\end{tabular}
\end{document}

enter image description here

The \alignLongstack can be placed directly within the tabular itself if the tab character and the end-of-line character are changed (from & and \\) and if the long stacking gap is defined in terms of actual distance, rather than \baselineskip, since tabular apparently changes the value.

\documentclass[a4paper, 12pt]{scrreprt}
\usepackage{tabstackengine}
\strutlongstacks{T}
\begin{document}
\setstackTAB{\&}
\setstackEOL{*}
\setstackgap{L}{2.7ex}
\begin{tabular}{c}
\hline
\alignLongstack{
\&Test1 \&\&\rlap{~~~Test2}\&\&\&\&\rlap{~~~Tests3}\&\&\&*
\&Observations successful \& no\&   \& ye\&s    \& may\&be \& no\&*
\& adsadad\& 546546.\&546 \& 45.\&646 \& 45.\&646   \& 456.\&456*
\&\% AAA  \& 235.\&25\%   \& 2525\&\% \& 2342.\&34\% \& 234.\&2525\%*
\&\% BBB  \& 0.\&0029     \&     N/\&A  \& 0.\&0031 \& N/\&A*
\&\% CCC  \& 0.\&0033     \&     N/\&A  \& 0.\&0031 \& N/\&A  
}\\
\hline
\end{tabular}
\end{document}

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.