3

I have a table in my document, because of long text, I used tabulary. Now I have a problem with it. Because it didn't support setting middle. What should I do now? Change my tabulary package?

\documentclass[a4paper]{article}
\usepackage{tabulary}

\begin {document}

    \begin {table}[h]
    \centering
    \label{t4}
    \renewcommand{\arraystretch}{1.5}
    \begin{tabulary}{\textwidth}{RCCCC}
    A long title that is wrapped on several lines & A long title that is wrapped on several lines & A long title that is wrapped on several lines \\
    \hline 
    A random text & 1 & 0.025 \\
    \hline
    A quite long random text (wrapped on 3 lines)  & 2 & 2 \\
    \hline
    A quite long random text (wrapped on 3 lines)  & 2 & 2 \\
    \hline

    \end{tabulary}
    \end{table}

\end{document}

enter image description here

1

Try the tabu package.

\documentclass[a4paper]{article}
\usepackage{tabu}
\begin{document}
\begin {table}[h]
\centering
\tabulinesep = 3pt
\begin{tabu}to \linewidth{X[1, r, m]*2{X[1, c, m]}}
A long title that is wrapped on several lines & A long title that is wrapped on several lines & A long title that is wrapped on several lines \\
\hline
A random text & 1 & 0.025 \\
\hline
A quite long random text (wrapped on 3 lines)  & 2 & 2 \\
\hline
A quite long random text (wrapped on 3 lines)  & 2 & 2 \\
\hline
\end{tabu}
\end{table}
\end{document}

| improve this answer | |
1

Another solution by declaring two new colummn types: \newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}} and \newcolumntype{R}[1]{>{\raggedleft\arraybackslash}m{#1}}. You can manually adjust the width by C{width} and R{width}.

MWE

\documentclass[a4paper]{article}
\usepackage{tabularx}

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

\begin{document}

    \begin{table}[h]
    \centering
    \label{t4}
    \renewcommand{\arraystretch}{1.5}
    \begin{tabular}{R{3cm}C{3cm}C{3cm}}
    A long title that is wrapped on several lines & A long title that is wrapped on several lines & A long title that is wrapped on several lines \\
    \hline 
    A random text & 1 & 0.025 \\
    \hline
    A quite long random text (wrapped on 3 lines)  & 2 & 2 \\
    \hline
    A quite long random text (wrapped on 3 lines)  & 2 & 2 \\
    \hline
    \end{tabular}
    \end{table}

\end{document}
| improve this answer | |

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.