1

Would like to adjust the table in better looking, tried both methods, not working.

Make the first column letter into 2 row. Make all the content to left-hand side All the column around same length

enter image description here

enter image description here

\documentclass[12pt,oneside]{book}

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

\usepackage{makecell,siunitx}
\usepackage{booktabs}
\usepackage{tabulary,siunitx}
\usepackage{makecell, multirow, tabularx} %for table multirow
%for table multirow

\begin{document} 


\renewcommand\theadfont{\small\bfseries} 
\begin{table}[!ht]
\centering
\begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}Xcclc}
    \toprule
     \thead[l]{}
     & 
     & \thead{Value Label}
     & \thead{N}
     \\
     \midrule
    \multirow{2}{*}{\textbf{Example}}  & 1 & Example Example Example & 20\\
\cline{2-4} 
    & 2 & Example Example Example Example & 20 \\
\cline{1-4}
        \multirow{2}{*}{\textbf{Example Example Example}}  & 1 & AM & 20\\
\cline{2-4}
    & 2 & FM & 20 \\
    \bottomrule
    \end{tabularx}
\end{table}


\setlength\extrarowheight{1pt}          
\renewcommand{\arraystretch}{1.2}
\begin{table}[h!]
\centering
    \begin{tabularx}{\textwidth}{@{}Y*{3}{W}@{}}
    \toprule
     & 
     & \small {\textbf{Value Label}} & \small {\textbf{N}}
     \\
     \midrule
    \multirow{2}{*}{\textbf{Example}}  & 1 & Example Example Example & 20\\
\cline{2-4} 
    & 2 & Example Example Example Example & 20 \\
\cline{1-4}
        \multirow{2}{*}{\textbf{Example Example Example}}  & 1 & AM & 20\\
\cline{2-4}
    & 2 & FM & 20 \\
    \bottomrule
    \end{tabularx}
\end{table}


\end{document}
3
  • Instead of \multirow{2}{*}{... use \multirow{2}{\hsize}{..., see tex.stackexchange.com/a/73169.
    – user194703
    Sep 2, 2019 at 3:06
  • Please make your code compilable. How are the Y and W type columns definded?
    – leandriis
    Sep 2, 2019 at 7:05
  • Please see if you get the desired result if you use \begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}Xlll}, \multirow{2}{=}{...} and replace \cline with \cmidrule
    – leandriis
    Sep 2, 2019 at 7:09

1 Answer 1

4

Changing {*} to {=} fixes the linebreak in multirows when you change first and third column to a left aligned X column. To reduce typing, I defined such column as a new columntype. In addition, by using array's new w column, you can fix both width and alignment. I fixed the width to 2 cm, but change those values if you prefer wider or narrower second and fourth column.

Example 1

Since you cannot use a new version of array, I changed the second and fourth column to a fixed width p-column, with contents centred. For readability, I defined a new columntype V. In addition, I limited the width of the whole tabular to 0.7\linewidth. I also chosed fontsize \small.

enter image description here

\documentclass[12pt,oneside]{book}

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

\usepackage{makecell,siunitx}
\usepackage{booktabs, array}
\usepackage{tabulary,siunitx}
\usepackage{makecell, multirow, tabularx} %for table multirow
%for table multirow

\begin{document} 



\setlength\extrarowheight{1pt}          
\renewcommand{\arraystretch}{1.2}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\newcolumntype{V}{>{\centering\arraybackslash}p{1cm}}  % Centred fix width column

\begin{table}
\small
\centering
    \begin{tabularx}{0.7\textwidth}{@{}YVYV@{}}  % Limit the width of the tabular
    \toprule
     & 
     & \small {\textbf{Value Label}} & \small {\textbf{N}}
     \\
     \midrule
    \multirow{2}{*}{\textbf{Example}}  & 1 & Example Example Example & 20\\
\cmidrule{2-4} 
    & 2 & Example Example Example Example & 20 \\
\cmidrule{1-4}
        \multirow{2}{=}{\textbf{Example Example\newline Example}}  & 1 & AM & 20\\
\cmidrule{2-4}
    & 2 & FM & 20 \\
    \bottomrule
    \end{tabularx}
\end{table}

\end{document}

Example 2

enter image description here

\documentclass[12pt,oneside]{book}

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

\usepackage{makecell,siunitx}
\usepackage{booktabs, array}
\usepackage{tabulary,siunitx}
\usepackage{makecell, multirow, tabularx} %for table multirow
%for table multirow

\begin{document} 



\setlength\extrarowheight{1pt}          
\renewcommand{\arraystretch}{1.2}
\newcolumntype{Y}{>{\raggedright\arraybackslash}X}
\begin{table}
\centering
    \begin{tabularx}{\textwidth}{@{}Yw{c}{2cm}Yw{c}{2cm}@{}}
    \toprule
     & 
     & \small {\textbf{Value Label}} & \small {\textbf{N}}
     \\
     \midrule
    \multirow{2}{*}{\textbf{Example}}  & 1 & Example Example Example & 20\\
\cmidrule{2-4} 
    & 2 & Example Example Example Example & 20 \\
\cmidrule{1-4}
        \multirow{2}{=}{\textbf{Example Example\newline Example}}  & 1 & AM & 20\\
\cmidrule{2-4}
    & 2 & FM & 20 \\
    \bottomrule
    \end{tabularx}
\end{table}


\end{document}
2
  • i run in Overleaf, and it said have Package array Error: Illegal pream-token(w):'c@ used and Illegal pream-token (2cm):c used. Secondly, how to make it more compact rather than spread out the whole length.
    – aan
    Sep 2, 2019 at 13:32
  • 1
    Overleaf use an very old version of LateX distribution, where w and W columns was not implemented. You may upload a more recent array version to you r project file, but is this does not work, I will suggest a second alternative. Hold on for some minutes.
    – Sveinung
    Sep 2, 2019 at 13:35

You must log in to answer this question.

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