1

I have a multicolum table but the table doesn't fit the page width in order to obtain this setting

enter image description here

When I run the latex, also using \begin{adjustbox}{width=\textwidth}, I get this result

enter image description here

\documentclass[12pt]{article}
    \usepackage{tabularx}
    \usepackage{graphicx}
    \usepackage{adjustbox}


\begin{document}

\begin{table}[ht]
\centering
\begin{adjustbox}{width=\textwidth}
\begin{tabular}{|l|l|l|l|l|} \hline
    \textbf{Course Title} 
    & \textbf{Instructor}   
    & \textbf{Credit} 
    & \textbf{Teaching hours} 
    & \textbf{Pass grade} \\ \hline
    Programming Methodologies & 
    Prof. Alan Turing & 
    9 & 
    72 & 
    28/30 \\ \hline
    \multicolumn{5}{|l|}{\textbf{Course~Content} } \\ \hline
    \multicolumn{5}{|l|}{\begin{tabular}[c]{@{}l@{}}Oject-oriented techniques for software construction: design principles and language features in order to achieve extendibility, reusability and compatibility. Classes, Encapsulation and Information Hiding. UML (Unified Modeling Language): the class diagram for analysis, design and documentation.~Inheritance. Object composition and delegation. Abstract classes. Classes as Types. Polymorphism by subtyping and Genericity.\\Object-oriented Programming in Java. Using JUnit for automated tests. Design principles and clean code. Design Patterns.\end{tabular}} \\ \hline
\end{tabular}
\end{adjustbox}
\end{table}


\end{document}
3

Your table is too wide, and you must introduce line breaks using p-columns. It is better to reduce the font size for the whole table, avoid \adjustbox because it distorts the font. See example 2.

A better solution is to use tabulary and combine ordinary LR-column and tabulary's C column. tabulary is able to calculate the column space correctly, as you will see from example 1.

Of cause, if you have multiple similar tabulars, you may be better of using fixed width columns so all tabulars look similar.

Example 1 - tabulary

enter image description here

\documentclass[12pt]{article}
\usepackage{tabulary, ragged2e}
\setlength{\extrarowheight}{2pt}

\begin{document}
\begin{table}[!ht]
\centering
\footnotesize
\begin{tabulary}{\linewidth}{|*{2}{l|}c|*{2}{C|}} \hline
    \textbf{Course Title} 
    & \textbf{Instructor}   
    & \textbf{Credit} 
    & \textbf{Teaching hours} 
    & \textbf{Pass grade} \\ \hline
    Programming Methodologies & 
    Prof. Alan Turing & 
    9 & 
    72 & 
    28/30 \\ \hline
    \multicolumn{5}{|l|}{\textbf{Course~Content} } \\ \hline
    \multicolumn{5}{|>{\RaggedRight\arraybackslash}p{\dimexpr \linewidth - 2\tabcolsep - 2\arrayrulewidth}|}{\emph{Object-oriented techniques for software construction}: design principles and language features in order to achieve extendibility, reusability and compatibility. Classes, Encapsulation and Information Hiding. \newline
        \emph{UML (Unified Modeling Language)}: the class diagram for analysis, design and documentation.~Inheritance. Object composition and delegation. Abstract classes. Classes as Types. Polymorphism by subtyping and Genericity.\newline
        \emph{Object-oriented Programming in Java}: Using JUnit for automated tests. Design principles and clean code. Design Patterns.} \\ \hline
\end{tabulary}
\end{table}
\end{document}

Example 2

enter image description here

\documentclass[12pt]{article}
    \usepackage{tabularx}
    \usepackage{graphicx}
    \usepackage{adjustbox}


\begin{document}

\begin{table}[ht]
\centering
\footnotesize
\begin{tabular}{|p{3cm}|l|l|p{1.5cm}|l|} \hline
    \textbf{Course Title} 
    & \textbf{Instructor}   
    & \textbf{Credit} 
    & \textbf{Teaching hours} 
    & \textbf{Pass grade} \\ \hline
    Programming Methodologies & 
    Prof. Alan Turing & 
    9 & 
    72 & 
    28/30 \\ \hline
    \multicolumn{5}{|l|}{\textbf{Course~Content} } \\ \hline
    \multicolumn{5}{|p{\dimexpr \linewidth - 2\tabcolsep - 2\arrayrulewidth}|}{Object-oriented techniques for software construction: design principles and language features in order to achieve extendibility, reusability and compatibility. Classes, Encapsulation and Information Hiding. UML (Unified Modeling Language): the class diagram for analysis, design and documentation.~Inheritance. Object composition and delegation. Abstract classes. Classes as Types. Polymorphism by subtyping and Genericity.\\Object-oriented Programming in Java. Using JUnit for automated tests. Design principles and clean code. Design Patterns.\end{tabular}} \\ \hline
\end{tabular}
\end{table}
\end{document}
3
  • 1
    Wouldn't a simple \multicolumn{5}{|p{\dimexpr \linewidth - 2\tabcolsep - 2\arrayrulewidth}|}{...} be sufficient? – leandriis May 25 '20 at 18:19
  • @leandriis Of course you are right, I only only adapted OP code. I will correct it. Also, tabulary will work much better. – Sveinung May 25 '20 at 18:48
  • 1
    @leandriis tabulary made the difference! – Sveinung May 25 '20 at 19:34
2

A solution with tabularx and makecell:

\documentclass[12pt]{article}
\usepackage{tabularx, makecell}
\renewcommand{\theadfont}{\normalsize\bfseries}
\usepackage{showframe}
\renewcommand{\ShowFrameLinethickness}{0.2pt}

\begin{document}

\begin{table}[ht]
\centering
\setlength{\extrarowheight}{2pt}
\begin{tabularx}{\linewidth}{|>{\hsize=0.9\hsize}X|>{\hsize=1.1\hsize}X|l|l|l|} \hline
    \textbf{Course Title}
    & \textbf{Instructor}
    & \textbf{Credit}
    & \thead[l]{Teaching\\ hours}
    & \thead[l]{Pass grade} \\ \hline
    \makecell[l]{Programming\\ Methodologies} &
    Prof. Alan Turing &
    9 &
    72 &
    28/30 \\ \hline
    \multicolumn{5}{|l|}{\textbf{Course~Content}} \\ \hline
 \multicolumn{5}{|p{\dimexpr\textwidth-2\tabcolsep}|}{Object-oriented techniques for software construction: design principles and language features in order to achieve extendibility, reusability and compatibility. Classes, Encapsulation and Information Hiding. UML (Unified Modeling Language): the class diagram for analysis, design and documentation.~Inheritance. Object composition and delegation. Abstract classes. Classes as Types. Polymorphism by subtyping and Genericity.\par Object-oriented Programming in Java. Using JUnit for automated tests. Design principles and clean code. Design Patterns. } \\ \hline
\end{tabularx}
\end{table}

\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.