1

I need to know how to wrap text in MWE. I have already seen some answered questions on that. But it only added more confusion to me. I am a beginner in Latex. I need to give a table in an A3 page in A4 document. I have not added this in the MWE. MWE is :

\documentclass[12pt]{report} 
\usepackage{float}
\begin{document}
\begin{table}[H]
    \centering
    \caption{Indirect Include Dependency for Sched Module}
    \begin{tabular}{|l|l|l|l|l|l|l|l|l|}
    \hline
    \textbf{Modules} & \textbf{sched.h} & \textbf{completion.h} &    \textbf{cpu.h} & \textbf{cpuidle.h} & \textbf{kernel\_stat.h} & \textbf{swait.h} & \textbf{wait.h} & \textbf{Total} \\ \hline
    arch & 984 & 15 & 214 & 20 & 106 & 1 & 49 & \textbf{1 389} \\ \hline
    block & 1 & 2 & 3 &  & 1 &  & 1 & \textbf{8} \\ \hline
    \end{tabular}
    \end{table}
\end{document}
  • Given that the header cells contain single words, where is text wrapping supposed to take place? – Mico Sep 6 '17 at 20:29
0

I suggest you change the font size inside the table environment to \footnotesize and use a tabular* environment instead of a tabular environment, to assure that the table occupies the width of the textblock. I would use the c column type for the 8 data columns, and I would not use bold in the header row. Finally, do give the table a more open look by getting rid of all vertical rules and using fewer, but well-spaced, horizontal rules.

enter image description here

\documentclass[12pt,a4paper]{report} 
\usepackage{booktabs,caption}
\begin{document}

\begin{table}
\captionsetup{font=small,skip=0.25\baselineskip}
\caption{Indirect Include Dependency for Sched Module}
\footnotesize
\setlength\tabcolsep{0pt} % let LaTeX figure out intercolumn whitespace

    \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l *{8}{c} }
    \toprule
    Modules & sched.h & completion.h & cpu.h & cpuidle.h & 
    kernel\_stat.h & swait.h & wait.h & Total \\ 
    \midrule
    arch & 984 & 15 & 214 & 20 & 106 & 1 & 49 & \textbf{1 389} \\ 
    %\hline
    block & 1 & 2 & 3 &  & 1 &  & 1 & \textbf{8} \\ 
    \bottomrule
    \end{tabular*}

\end{table}
\end{document}
1

Based on compiling your MWE I assume that you mean you want the table to fit on one page since it doesn't actually do so now and since you don't have any actual text within the columns which would need to wrap (such as multiple words or a sentence or some such). In this case I use the graphicx package and resizebox{}{}{} to do so. resizebox takes the arguments resizebox{<height>}{<width>}{<box_content>} and you can retain the aspect ratio while resizing the box to the text with by giving ! as the first argument and \textwidth as the second (or whatever specific size you desire). Based on this your MWE would be:

\documentclass[12pt]{report} 
\usepackage{float}
\usepackage{graphicx}%%Add graphicx
\begin{document}
    \begin{table}[!htbp] %%unless you have to specify a position, I find it best to let LaTeX decide
    \centering
    \caption{Indirect Include Dependency for Sched Module}
    \resizebox{\textwidth}{!}{ %%begin resize box
        \begin{tabular}{|l|l|l|l|l|l|l|l|l|}
        \hline
        \textbf{Modules} & \textbf{sched.h} & \textbf{completion.h} &    
        \textbf{cpu.h} & \textbf{cpuidle.h} & \textbf{kernel\_stat.h} & 
        \textbf{swait.h} & \textbf{wait.h} & \textbf{Total} \\ \hline
        arch & 984 & 15 & 214 & 20 & 106 & 1 & 49 & \textbf{1 389} \\ 
        \hline
        block & 1 & 2 & 3 &  & 1 &  & 1 & \textbf{8} \\ \hline
\end{tabular}
}%%Important to close your box!!
\end{table}
\end{document}
0

enter image description here

threeparttable enable use of notes, where is explained meaning of used abbreviation of longer columns headers. by use of abbreviation the fonts in table can stay normal size. with siunitx numbers in column are right aligned but centered in cells:

\documentclass[12pt,a4paper]{report}
\usepackage{booktabs,tabularx,threeparttable}
\usepackage{siunitx}
\usepackage{caption}

\usepackage{etoolbox}
\renewcommand{\bfseries}{\fontseries{b}\selectfont} % <--
\robustify\bfseries                                 % <--
\newrobustcmd{\BF}{\bfseries}                       % <-- schortcut

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{table}
\captionsetup{font=small,skip=0.25\baselineskip}
\sisetup{detect-weight,
         mode=text,
         group-minimum-digits=4,
          }
\begin{threeparttable}[htb]
    \caption{Indirect Include Dependency for Sched Module}
\setlength\tabcolsep{3pt}
    \begin{tabular*}{\textwidth}{l
                                 @{\extracolsep{\fill}}
                                 S[table-format=3.0]
                                 S[table-format=2.0]
                                 S[table-format=3.0]
                                 S[table-format=2.0]
                                 S[table-format=3.0]
                            *{2}{S[table-format=2.0]}
                                 S[table-format=4.0]
                                 }
    \toprule
Modules & {sched.h}         & {comp.\tnote{a}}
        & {cpu.h}           & {cpuidle.h}
        & {k\_s\tnote{b}}   & {swait.h }
        & {wait.h}          & {Total}                       \\
\midrule
arch    & 984 & 15 & 214 & 20 & 106 & 1 & 49 & \BF   1 389  \\
block   &   1 &  2 &   3 &    & 1   &   &  1 & \BF       8  \\
\bottomrule
    \end{tabular*}
    \begin{tablenotes}[para,flushleft]\small
\item[a] comp.: completion.h;
\item[b] k\_s:  kernel\_stat.h.
    \end{tablenotes}
\end{threeparttable}
    \end{table}
\end{document}

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.