我怎样才能解决这个问题?

我怎样才能解决这个问题?

如何在 LaTex 中制作下表: 在此处输入图片描述

我尝试了以下操作:

\documentclass[10pt, a4paper]{article}

%Some packages I commonly use.

\usepackage{graphicx}
\usepackage[colorlinks]{hyperref}

\usepackage{xcolor} %For coloring texts and objects

\usepackage{enumerate}
\usepackage{enumitem}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage{multirow}

\usepackage{amssymb}
\usepackage[utf8]{inputenc} % to allow characters beyond ASCII (e.g. à, ü, č ...)
\usepackage[top=1 in,bottom=1in, left=1 in, right=1 in]{geometry}
\usepackage{lipsum}
%\usepackage{authblk} %For Author Titling and affiliating Purpose

\begin{document}
    \begin{tabular}{ |p{2.5cm}|p{2cm}|p{2cm}|p{2cm}|p{1.2cm}|p{1.2cm}|p{3cm}|}
        \hline
        \multirow{2}{*}{Name of Student / Teacher} & 
        \multirow{2}{*}{Years of Study} & 
        \multicolumn{2}{c|}{Subjects} &
        \multirow{2}{*}{Years of Passing} &
        \multirow{2}{*}{Class/rank /distinction} &
        \multirow{2}{*}{University/ Institute} \\
        \cline{3-4}& & Main & Subsidiary & & & \\
        \hline
        
        Science & 2013-2016 & Mathematics & Physcs, Chemistry & 1929 &  & Name of the University Here\\
        \hline
        Name & 2016-2018 & Biology & Chems & 1997 &   & University Name Here\\
        \hline
        (Last item) & & & & & &\\
        \hline
    \end{tabular}
\end{document}

但是单元格中的文本彼此重叠了。

我的输出

在此处输入图片描述

我该如何修复这个问题?谢谢。

编辑 根据评论中的建议,我对其进行了如下修改

\documentclass[10pt, a4paper]{article}

%Some packages I commonly use.

\usepackage{graphicx}
\usepackage[colorlinks]{hyperref}

\usepackage{xcolor} %For coloring texts and objects

\usepackage{enumerate}
\usepackage{enumitem}
\usepackage{booktabs}
\usepackage{multicol}
\usepackage{multirow}

\usepackage{amssymb}
\usepackage[utf8]{inputenc} % to allow characters beyond ASCII (e.g. à, ü, č ...)
\usepackage[top=1 in,bottom=1in, left=1 in, right=1 in]{geometry}
\usepackage{lipsum}
%\usepackage{authblk} %For Author Titling and affiliating Purpose

\begin{document}
    \begin{tabular}{ |p{2.5cm}|p{2cm}|p{2cm}|p{2cm}|p{1.2cm}|p{1.2cm}|p{3cm}|}
        \hline
        \multirow{2}{=}{Name of Student / Teacher} & 
        \multirow{2}{=}{Years of Study} & 
        \multicolumn{2}{c|}{Subjects} &
        \multirow{2}{=}{Years of Passing} &
        \multirow{2}{=}{Class/rank /distinction} &
        \multirow{2}{=}{University/ Institute} \\
        \cline{3-4}& & Main & Subsidiary & & & \\
        \hline
        
        Science & 2013-2016 & Mathematics & Physcs, Chemistry & 1929 &  & Name of the University Here\\
        \hline
        Name & 2016-2018 & Biology & Chems & 1997 &   & University Name Here\\
        \hline
        (Last item) & & & & & &\\
        \hline
    \end{tabular}
\end{document}

新产出

在此处输入图片描述

但这仍然不是我想要的。

答案1

根据要求,提供一个字体大小不变的版本。为了确保表格适合可用的文本宽度,我使用了该tabularx包并更改了一些列宽。

在此处输入图片描述

\documentclass[10pt, a4paper]{article}


\usepackage{tabularx}
\usepackage{multirow}
\usepackage[top=1 in,bottom=1in, left=1 in, right=1 in]{geometry}


\begin{document}

\noindent
    \begin{tabularx}{\linewidth}{ |p{1.8cm}|p{2cm}|p{2cm}|p{2cm}|p{1.2cm}|p{1.8cm}|X|}
        \hline
        \multirow{3}{=}{Name of Student / Teacher} & 
        \multirow{3}{=}{Years of Study} & 
        \multicolumn{2}{c|}{Subjects} &
        \multirow{3}{=}{Years of Passing} &
        \multirow{3}{=}{Class/rank /distinction} &
        \multirow{3}{=}{University/ Institute} \\
        \cline{3-4}& & \multirow{2}{=}{Main} & \multirow{2}{=}{Subsidiary} & & & \\
        &&&&&&\\
        \hline
        
        Science & 2013--2016 & Mathematics & Physcs, Chemistry & 1929 &  & Name of the University Here\\
        \hline
        Name & 2016--2018 & Biology & Chems & 1997 &   & University Name Here\\
        \hline
        (Last item) & & & & & &\\
        \hline
    \end{tabularx}
\end{document}

答案2

无关:

  • 该包hyperref应该在序言中最后加载
  • 不要使用enumerate˙ andenumitem` 包,请只使用其中一个
  • 不要担心使用一些可以简化代码并提供更好结果的新包

关于主题:

  • 使用tabularray包解决方案非常简单:
\documentclass{article}
\usepackage[a4paper,
            margin=25mm]{geometry}
\usepackage{tabularray}

\begin{document}
\noindent%
    \begin{tblr}{colspec={|X[1.3]|X[0.8] |X[1.1]|X[0.9] |X[0.8,c]|X[0.8] |X|X[1.5]|},
                 colsep=3pt,
                 rowsep=3pt,
                 hline{1,6}={1pt}, hline{3}=0.6pt,
                 hlines
                }
\multirow{2}{=}{Name of Student/ Teacher} 
    &   \multirow{2}{=}{Years of Study} 
        &   \multicolumn{2}{c|}{Subjects} 
                &   \multirow{2}{=}{Years of Passing}
                    &   \multirow{2}{=}{Class/ rank/ distinction}
                        &   \multirow{2}{=}{University/ Institute} \\
    \cline{3-4}
    &   &   Main 
            &   Subsidiary 
                &   &   &                                           \\
Science 
    & 2013-2016 
        & Mathematics 
            & Physcs, Chemistry 
                & 1929 
                    &   & Name of the University Here               \\
Name 
    & 2016-2018 
        & Biology 
            & Chems 
                & 1997
                    &   & University Name Here                      \\
(Last item) 
    &   &   &   &   &   &                                           \\
    \end{tblr}
\end{document}

在此处输入图片描述

(红线表示文字边框)

答案3

像这样吗?(注意:\multirow目之所及之处,没有一个是这样的……)

在此处输入图片描述

\documentclass[10pt,a4paper]{article}
%\input{structure} % I don't have access to 'structure.tex'
\usepackage[margin=2.5cm]{geometry} % or whatever is appropriate
\usepackage{array,ragged2e}
\newcolumntype{M}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}
% utility macro for typesetting header cells:
\newcommand\mytab[1]{%
   \smash{\begin{tabular}[t]{@{} M{\hsize} @{}} #1 \end{tabular}}}
   
\begin{document}
\noindent
\begin{tabular}{ |M{2.1cm}|M{1.6cm}|M{1.8cm}|M{1.8cm}|M{1.4cm}|M{2.0cm}|M{2.2cm}|}
        \hline
        \mytab{Name of Student\slash Teacher} & 
        \mytab{Years of Study} & 
        \multicolumn{2}{c|}{Subjects} &
        \mytab{Years of Passing} &
        \mytab{Class\slash rank\slash distinction} &
        \mytab{University\slash Institute} \\
        \cline{3-4}
        & & Main & Subsidiary & & & \\
        \hline
        
        Science & 2013--2016 & Mathematics & Physics, Chemistry & 1929 &  & Name of university here\\
        \hline
        Name & 2016--2018 & Biology & Chems & 1997 &   & University name here\\
        \hline
        (Last item) & & & & & &\\
        \hline
    \end{tabular}
\end{document}

相关内容