0

As a bit of a newbie, I am having some trouble with the multirow/multicolumn setup in this table. I am trying to have all the cells with centered text and automatic line breaks, however I can not get these features to work in the multirow cell. As you can see, the text in the multirow is centered correctly at the moment, but the way in which I achieved this seems rather 'bodgy'. Is the correct solution to use \centering in this row or is there a more elegant solution (such as using the equivalent of a columntype)?

Next is a multicolumn problem. The x and y should be equidistant to each other and the vertical lines on their respective sides. I have tried a couple ways to do this using the different columntypes, but I either end up with incorrectly spaced letters or correctly spaced letters but incorrectly placed vertical lines (such as using \multicolumn{3}{c|}{\hfill x \hfill y } \hfill).

I would like to approximately preserve the current spacing of the rows, if possible. Additionally, I don't understand why if I set the first row to C{.3\textwidth} the whole table does not add up to 100% of the text width, but overshoots the right margin. I'm currently using the Y columntype only because it makes the vertical borders of the table fit...

\documentclass[12pt]{article}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}


\usepackage{geometry}
\geometry{a4paper,left=25mm,right=25mm}


\usepackage{tabularx}
\usepackage{multirow}


\newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
\newcolumntype{Y}{>{\centering\arraybackslash}X}

\begin{document}

\noindent
\begin{tabularx}{\textwidth}{ | Y | C{.25\textwidth} | C{.15\textwidth} | C{.15\textwidth} | C{.15\textwidth} | }
\hline
Some centered text here & A bunch of words too long for one line & A bunch of words too long for one line & A bunch of words too long for one line & A bunch of words too long for one line \\
\hline
\multirow{2}{\hsize}{\centering this should be centered} & a line of words & a & b & c \\ 
\cline{2-5}
 & a line of words & a & b & c \\
\hline
\hline
a line of words & a line of words & \multicolumn{3}{l|}{\hfill x \hfill y \hfill} \\
\hline
\end{tabularx}
\end{document}
2
  • 2
    if you fix the first column at .3\textwidth the table is too wide because you have 10\tabcolsep padding from 5 columns and 6 \arrayrulewidth from the vertical rules. You could adjust for that but then you should use tabular not tabularx as tabularx has to have at least one X column. Oct 10, 2018 at 17:22
  • @DavidCarlisle That's a good bit of information to know, thank you!
    – TivV
    Oct 10, 2018 at 18:26

1 Answer 1

2

For the multirow problem, you can redefine \multirowsetup, which is \raggedright by default. For the multicolumn problem, I propose a solution, but I'm not sure I've well understood what you want exactly.

    \documentclass[12pt]{article}

    \usepackage[T1]{fontenc}
    \usepackage[utf8]{inputenc}

    \usepackage{geometry}
    \geometry{a4paper,left=25mm,right=25mm, showframe}
    \usepackage{tabularx}
    \usepackage{multirow}

    \newcolumntype{L}[1]{>{\raggedright\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
    \newcolumntype{C}[1]{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
    \newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}m{#1}}
    \newcolumntype{Y}{>{\centering\arraybackslash}X}

    \begin{document}

   {\centering\setlength{\extrarowheight}{2pt}\small
    \renewcommand{\multirowsetup}{\centering}
    \begin{tabularx}{\textwidth}{ | Y | C{.25\textwidth} | C{.15\textwidth} | C{.15\textwidth} | C{.15\textwidth} | }
    \hline
    Some centered text here & A bunch of words too long for one line & A bunch of words too long for one line & A bunch of words too long for one line & A bunch of words too long for one line \\
    \hline
    \multirow{2}{=}{ this text is centered} & a line of words & a & b & c \\
    \cline{2-5}
     & a line of words & a & b & c \\
    \hline
    \hline
    a line of words & a line of words & \multicolumn{1}{c}{} & \multicolumn{1}{!{\makebox[0pt]{x}}c!{\makebox[0pt]{y}}}{} & \\
    \hline
    \end{tabularx}}
    \end{document} 

enter image description here

2
  • Thank you very much. The multirow solution is exactly the kind of thing I was looking for. As for the column, what I had in mind was that the x should in this case (where all the rows have the same width) be directly under the vertical rule separating the "a"s from the "b"s, and the y should be underneath the vertical rule separating the "b"s from the "c"s... I know this is very particular, sorry :)
    – TivV
    Oct 10, 2018 at 19:59
  • I've modified the code. Is that what you want now?
    – Bernard
    Oct 10, 2018 at 20:31

You must log in to answer this question.

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