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}
tabular
nottabularx
astabularx
has to have at least one X column.