1

I want to make table (using multirow and multicolumn). I want "Variable Influence" and "Description" is vertically centered and I don't want first column and last column is overlap with others column (even though I use tabularx). How to change it?

This is my code

\documentclass[a4paper,12pt,twoside]{article}
\usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
\usepackage{multirow}
\usepackage{placeins}
\usepackage{tabularx}
\usepackage{mathptmx}
\begin{document}
    \FloatBarrier
    \begin{table}[h]
        \caption{The Results of Discrimination Tests on Government Institution $X$ and Educational Institution $X$}
        \centering
        \label{tab6}
        \begin{tabularx}{\textwidth}{XXXXXXX}
            \hline
            \multirow{2}{*}{\textbf{Variable Influence}}&
            \multicolumn{2}{c}{\textbf{Goverment Institution $X$}}&\multicolumn{2}{c}{\textbf{Educational Institution $X$}}&\textbf{discrimination test results}&\multirow{2}{*}{\textbf{Description}}\\
            \cline{2-6}
            &\textbf{Coefficient Path}&\textit{\textbf{Standard Error}}&\textbf{Coefficient Path}&\textit{\textbf{Standard Error}}&\textbf{P-value}&\\
            \hline
        \end{tabularx}
    \end{table}
    \FloatBarrier
\end{document}

enter image description here

8
  • 1
    \multirow{2}{=}{\textbf{Variable Influence}} should work for the first column.
    – leandriis
    Sep 22, 2019 at 12:13
  • Yes, but it is not vertically centered. Sep 22, 2019 at 12:15
  • Vertically center with respect to the text above and below the line?
    – leandriis
    Sep 22, 2019 at 12:15
  • Please also clarify: Do you explicitly want your table columns to have equal widths? Will your columns contain text that needs linebreaks or did you just use tabularx to get the linebreaks in the column headers?
    – leandriis
    Sep 22, 2019 at 12:16
  • 1
    \multirow{4}{=}{\textbf{Variable Influence}} should fix the problem with the first column header. However, fixing the problem with the overlap in the sixth/seventh column header is harder since the word "discrimination" is too long. Would you allow hyphenating this word?
    – leandriis
    Sep 22, 2019 at 12:25

1 Answer 1

3

Here are four different versions of your table using slightly different layouts. The captions of each table contain a breif description of how the respective layout was achieved:

enter image description here

\documentclass[a4paper,12pt,twoside]{article}
\usepackage[left=2.00cm, right=2.00cm, bottom=2.00cm, top=2.00cm]{geometry}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{mathptmx}

%% Only used for second example

\usepackage{makecell}
\renewcommand{\theadfont}{\bfseries}

%% Only used for third + fourth example
\usepackage{booktabs}
\begin{document}

    \begin{table}[h]
        \caption{With the help of tabularx, hyphenation of "discrimination"}
        \centering
        \label{tab6}
        \begin{tabularx}{\textwidth}{*{7}{X}}
            \hline
            \multirow{6}{=}{\textbf{Variable Influence}}&
            \multicolumn{2}{c}{\textbf{Goverment Institution $X$}}&
            \multicolumn{2}{c}{\textbf{Educational Institution $X$}}&
            \hspace{0pt}\textbf{discrimination test results}&
            \multirow{6}{=}{\textbf{Description}}\\
            \cline{2-6}
            &\textbf{Coefficient Path}&
            \textit{\textbf{Standard Error}}&
            \textbf{Coefficient Path}&
            \textit{\textbf{Standard Error}}&
            \textbf{P-value}&\\
            \hline
        \end{tabularx}
    \end{table}


  \begin{table}[h]
        \caption{Without tabularx, manual linebreaks with makecell, }
        \centering
        \label{tab6}
        \begin{tabular}{*{7}{c}}
            \hline
            \multirow{4}{*}{\thead{Variable\\ Influence}}&
            \multicolumn{2}{c}{\thead{Goverment\\ Institution $X$}}&
            \multicolumn{2}{c}{\thead{Educational\\ Institution $X$}}&
            \thead{discrimination\\ test results}&
            \multirow{4}{*}{\thead{Description}}\\
            \cline{2-6}
            &\thead{Coefficient\\ Path}&
            \itshape\thead{Standard\\ Error}&
            \thead{Coefficient\\ Path}&
            \itshape\thead{Standard\\ Error}&
            \thead{P-value}&\\
            \hline
        \end{tabular}
    \end{table}

  \begin{table}[h]
  \renewcommand{\theadfont}{\normalfont}
        \caption{Without tabularx, lines from booktabs, manual linebreaks in column headers with tabularx}
        \centering
        \label{tab6}
        \begin{tabular}{*{7}{c}}
            \toprule
            \multirow{4}{*}{\thead{Variable\\ Influence}}&
            \multicolumn{2}{c}{\thead{Goverment\\ Institution $X$}}&
            \multicolumn{2}{c}{\thead{Educational\\ Institution $X$}}&
            \thead{discrimination\\ test results}&
            \multirow{4}{*}{\thead{Description}}\\
            \cmidrule(r){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-6}
            &\thead{Coefficient\\ Path}&
            \itshape\thead{Standard\\ Error}&
            \thead{Coefficient\\ Path}&
            \itshape\thead{Standard\\ Error}&
            \thead{P-value}&\\
            \bottomrule
        \end{tabular}
    \end{table}

    \begin{table}[h]
        \caption{Equal column widths with tabularx, lines with booktabs}
        \centering
        \label{tab6}
        \begin{tabularx}{\textwidth}{*{7}{X}}
            \toprule
            \multirow{6}{=}{Variable Influence}&
            \multicolumn{2}{c}{Goverment Institution $X$}&
            \multicolumn{2}{c}{Educational Institution $X$}&
            \hspace{0pt}discrimination test results&
            \multirow{6}{=}{Description}\\
            \cmidrule(r){2-3} \cmidrule(lr){4-5} \cmidrule(l){6-6}
            &Coefficient Path&
            Standard Error&
            Coefficient Path&
            Standard Error&
            P-value&\\
            \bottomrule
        \end{tabularx}
    \end{table}
\end{document}
1
  • Thank you very much for helping me! It is very complete answer. Sep 22, 2019 at 12:40

You must log in to answer this question.

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