Search code examples
latextabularmultirow

An alternative to write multirow in latex's tabular?


In latex, I know we can use the multirow command like the following,

\begin{table}[!h]
    \centering
    \begin{tabular}{|c|l|}
        \hline
        \multirow{2}{*}{A}
        & I want to place this sentence in multiple lines, \\
        & but don't want to control the linebreak myself \\
        \hline
    \end{tabular}
\end{table}

enter image description here

I think it is so stupid to control the linebreak myself.

Any other alternative that fits the text width to line width?


Solution

  • \documentclass{article}
    
    \usepackage{tabularx}
    \renewcommand\tabularxcolumn[1]{m{#1}}
    
    \begin{document}
    
    \begin{table}[htbp]
        \centering
        \begin{tabularx}{\linewidth}{|c|X|}
            \hline
            A
            & I want to place this sentence in multiple lines, but don't want to control the linebreak myself \\
            \hline
        \end{tabularx}
    \end{table}
    
    \end{document}
    

    enter image description here