2

How to produce the following table in LaTex: enter image description here

I tried the following:

\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}

But my texts in the cells are getting overlapped with each other.

My Output

enter image description here

How can I fix this? Thanks.

EDIT As suggested in the comments I modified it as follows

\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}

New OUtput

enter image description here

Still it's not that what I want.

11
  • 1
    We do not have your file 'structure'. Would you please complete your code to a MWE with the relevant packages you use?
    – C. Peters
    Jul 10, 2021 at 10:08
  • Using \multirow{2}{=} instead of \multirow{2}{*} could be the first step.
    – leandriis
    Jul 10, 2021 at 10:09
  • @C.Peters I have added that portion here.
    – sigma
    Jul 10, 2021 at 10:11
  • @leandriis Okay I tried yours it gets better this time but some portion remains as before.
    – sigma
    Jul 10, 2021 at 10:14
  • 1
    You might want to consider a more informative title for your question. ;-)
    – Gaussler
    Jul 10, 2021 at 13:31

3 Answers 3

2

As requested a version in which the font size is not altered. In order to make sure, the table fits into the available text width, I used the tabularx package and altered some column widths.

enter image description here

\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}
1
  • @lendriis I used this in my original file but there the last column gets smaller and that's why texts in the last column is getting out of the table ! Can please you tell me how to fix this?
    – sigma
    Jul 10, 2021 at 10:39
5

Off-topic:

  • the package hyperref should be load the last in the preamble
  • don't use enumerate˙ and enumitem` packages, please use only one of them
  • don't affray to use some new package which can simplify your code and gives better result

On topic:

  • with the tabularray package solution is quite simple:
\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}

enter image description here

(red lines show text borders)

6
  • It gives the error: ``` File 'tabularray.sty' not found```
    – sigma
    Jul 10, 2021 at 12:57
  • @indrajit, this means that your LaTeX installation doesn't contain this package. Load it (by help of utility of your LaTeX installation, for example by MiKTeX Console, if you have MiKTeX).
    – Zarko
    Jul 10, 2021 at 13:02
  • I have MikTex console installed in my Ubuntu system. I tried to install the package with name tabularray but I didn't find any package with this name. Although I found a package named tabulary. Are they same?
    – sigma
    Jul 10, 2021 at 13:12
  • @indrajit: tabulary and tabularray are not the same package.
    – leandriis
    Jul 10, 2021 at 13:26
  • @indrajit, try to update your MiKTeX installation, refresh file names database and update package database.
    – Zarko
    Jul 10, 2021 at 13:47
4

Something like this? (Note: Not a single \multirow as far as the eye can see...)

enter image description here

\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}
3
  • Thanks for your answer. This does my job. Is it possible to get this output by using those packages which I have used originally?
    – sigma
    Jul 10, 2021 at 10:25
  • @indrajit - My solution uses the array package for its \newcolumntype macro and the ragged2e package for its \RaggedRight macro. Both your sample code and my solution make use of the geometry package. The nine other packages loaded by your sample code -- graphicx, hyperref, xcolor, enumerate, enumitem, booktabs, multicol, multirow, amssymb, and inputenc -- can not duplicate the machinery of the array and ragged2epackages. (But do note that you shouldn't load both enumerate and enumitem.)
    – Mico
    Jul 10, 2021 at 10:38
  • 1
    Thank you so much
    – sigma
    Jul 10, 2021 at 10:40

You must log in to answer this question.

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