1

The second column in the table is running into the right margin. Is there a way to control this without resizing the table? I'd like the text in this column to wrap.

\begin{table}[htbp]
  \centering
  \caption{My table}
    \begin{tabular}{lp{30.215em}}
    \textbf{Reason} & \multicolumn{1}{l}{\textbf{Explanation}} \\
    \hline
    \hline
    \textbf{Advancement} & Individual seeks academic progress and wants to secure the best possible education for oneself \\
    \hline
    \textbf{Bandwagon Thinking} & Individual participates in private tutoring as a result of influence of parents, peers, societal trends and mass media  \\
    \hline
    \textbf{Cookie-cutter} & Individual seeks one-shot solutions (ready-made answers, shortcuts, notes, question banks) to academic concerns  \\
    \hline
    \textbf{Cutting edge} & \multicolumn{1}{l}{Individual seeks superiority over classmates/peers} \\
    \hline
    \textbf{Deficit-Oriented} & Individual recognizes academic inadequacies and lack of academic support at school/home, and seeks said support from tutoring providers \\
    \hline
    \textbf{Forward looking } & Individual seeks tangible and intangible benefits in the future (high academic ranks, good job, favourable social status) \\
    \hline
    \end{tabular}
\end{table}
PGupta
  • 681
  • 1
    Take a look at the tabularx package. \begin{tabularx}{\textwidth}{lX} should work. Also, remove the \multicolumn{1}{l}command. – leandriis Jan 16 '21 at 11:33
  • 1
    Please state whether the column width of 30.215em is significant in some way and mustn't be changed. – Mico Jan 16 '21 at 11:36
  • 1
    @Mico Actually, you resolved the problem. Reducing this number fixed the issue. Thank you! – PGupta Jan 16 '21 at 11:39
  • 1
    you are replacing the p which would allow wrapping by l here \multicolumn{1}{l}{ forcing the column to be at least as wide as that text, is that intentional? – David Carlisle Jan 16 '21 at 11:40
  • By all means, do get rid of the \multicolumn{1}{l}{...} "wrappers". – Mico Jan 16 '21 at 11:44
  • @DavidCarlisle Actually I have used "Excel to Latex" plug-in (https://ctan.org/pkg/excel2latex?lang=en) so I don't know the relavance of the various options used. – PGupta Jan 16 '21 at 11:59
  • 1
    well l means make a single left aligned entry with no line breaking. You need to delete that if you want line breaking, Unless you need this data in excel for some other use there is little to be gained by relying on such an export tool. – David Carlisle Jan 16 '21 at 12:19

2 Answers2

2

With the use of tabularx, you can automatically adjust the table to the current textwidth. In the following MWE, I also included a second table with a slightly different design:

enter image description here

\documentclass{article}
\usepackage{tabularx}

\usepackage{calc} % for second example only \usepackage{booktabs} % for second example only \begin{document}

\begin{table} \centering \caption{My table} \begin{tabularx}{\textwidth}{lX} \textbf{Reason} & \textbf{Explanation} \ \hline \hline \textbf{Advancement} & Individual seeks academic progress and wants to secure the best possible education for oneself \ \hline \textbf{Bandwagon Thinking} & Individual participates in private tutoring as a result of influence of parents, peers, societal trends and mass media \ \hline \textbf{Cookie-cutter} & Individual seeks one-shot solutions (ready-made answers, shortcuts, notes, question banks) to academic concerns \ \hline \textbf{Cutting edge} & Individual seeks superiority over classmates/peers \ \hline \textbf{Deficit-Oriented} & Individual recognizes academic inadequacies and lack of academic support at school/home, and seeks said support from tutoring providers \ \hline \textbf{Forward looking } & Individual seeks tangible and intangible benefits in the future (high academic ranks, good job, favourable social status) \ \hline \end{tabularx} \end{table}

\begin{table} \centering \caption{My table} \begin{tabularx}{\textwidth}{>{\raggedright\arraybackslash}p{\widthof{Advancement}}X} \toprule Reason & Explanation \ \midrule Advancement & Individual seeks academic progress and wants to secure the best possible education for oneself \ \addlinespace Bandwagon Thinking & Individual participates in private tutoring as a result of influence of parents, peers, societal trends and mass media \ \addlinespace Cookie-cutter & Individual seeks one-shot solutions (ready-made answers, shortcuts, notes, question banks) to academic concerns \ \addlinespace Cutting edge & Individual seeks superiority over classmates/peers \ \addlinespace Deficit-Oriented & Individual recognizes academic inadequacies and lack of academic support at school/home, and seeks said support from tutoring providers \ \addlinespace Forward looking & Individual seeks tangible and intangible benefits in the future (high academic ranks, good job, favourable social status) \ \bottomrule \end{tabularx} \end{table}

\end{document}

leandriis
  • 62,593
0
\documentclass[10pt,a4paper]{article}

\begin{document}
     \begin{tabular}{lp{9cm}}
        \textbf{Reason} & \multicolumn{1}{l}{\textbf{Explanation}} \\
        \hline
        \hline
        \textbf{Advancement} & Individual seeks academic progress and wants to secure the best possible education for oneself \\
        \hline
        \textbf{Bandwagon Thinking} & Individual participates in private tutoring as a result of influence of parents, peers, societal trends and mass media  \\
        \hline
        \textbf{Cookie-cutter} & Individual seeks one-shot solutions (ready-made answers, shortcuts, notes, question banks) to academic concerns  \\
        \hline
        \textbf{Cutting edge} & \multicolumn{1}{l}{Individual seeks superiority over classmates/peers} \\
        \hline
        \textbf{Deficit-Oriented} & Individual recognizes academic inadequacies and lack of academic support at school/home, and seeks said support from tutoring providers \\
        \hline
        \textbf{Forward looking } & Individual seeks tangible and intangible benefits in the future (high academic ranks, good job, favourable social status) \\
        \hline
    \end{tabular}
\end{document}
js bibra
  • 21,280
  • 1
    If I compile your code, I still end up with a table being wider than the textwidth and a corresponding warning: "Overfull \hbox (57.45615pt too wide)" – leandriis Jan 16 '21 at 11:42
  • 1
    Also, if you don't embed a tabular-like environment in a table environment, be sure to prefix \noindent to it. – Mico Jan 16 '21 at 11:50