1

I want to create a very basic table with two columns. The second column should be made of one single cell (multirow). However, the text does not adjust to this single cell. Here's my code snippet:

\documentclass{article}
\usepackage[utf8]{inputenc}

\usepackage{tabularx}
\usepackage{tabulary}
\usepackage{multirow}
\usepackage[table]{xcolor}

\begin{document}
\begin{tabulary}{\textwidth}{ | l J |}
\hline
cell1 & \cellcolor{lightgray} \\
cell2 & \multirow{-2}{*}{\cellcolor{lightgray}single cell}\\
\hline
\end{tabulary}
\end{document}

Could someone teach me how to make the text fit in the single cell?

6
  • Welcome to TeX.SE! How the text should be text adjusted in multicolumn cell? Also please extend your code snippet to complete small document with your table, which we can test as it is.
    – Zarko
    Feb 28, 2020 at 1:54
  • I would like that the text fit in the "single cell" as a multiline text, respecting the page width (that's why I am using tabulary). As it is now, it is displayed as a single line text not bounded to the cell limits.
    – TylerD007
    Feb 28, 2020 at 2:01
  • (i) your table is text wide (ii) second J column in tabulary can be extent to the right border of text, so in your table is not meet the condition for automatic break of text into two lines since in cell is enough space for one line text! And please again, provide complete small document, as I already ask you.
    – Zarko
    Feb 28, 2020 at 2:06
  • I've already edited the original post with the small document. Should I replace J for which letter? With L or R, the problem still persists.
    – TylerD007
    Feb 28, 2020 at 2:09
  • Thank you, Zarko. It seems that substituting the {*} parameter by {=} solves the width issue. However, if the text is too long, it will still overflow the cell height. How could I fix this problem?
    – TylerD007
    Feb 28, 2020 at 2:21

1 Answer 1

2
  • Use option = for multirow cell. In this case, the cell width will be equal to column width
  • tabulary table environment adopt columns of type L, R, C and J to the width of cells content so that table width will be smaller or equal to the prescribed table width
  • height (or number of text lines) in multirow cell must be smaller or equal to the height (or number of text lines) of spanned rows in other columns.

An MWE (Minimal Working Example):

\documentclass{article}\usepackage{multirow, tabulary}
\usepackage[table]{xcolor}

\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}

\begin{document}
\noindent\begin{tabulary}{\textwidth}{ | l >{\columncolor{lightgray}}J |}
    \hline 
cell1 & \\
cell2 & \multirow{-2}{=}{single cell single cell single cell single cell single cell single cell single cell single}\\ 
    \hline
\end{tabulary}
\end{document}

enter image description here

(red lines indicate text borders)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .