3

I am trying to make a table with lots of columns. I specify width of each column. However, my text in column is overlapping the neighbouring column instead of going to new row.

How do I solve it?

See attached picture:

enter image description here

Code is as follows:

\begin{table}[h]
  \newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
  \setlength\extrarowheight{5pt}
  \scriptsize
  \centering
  \begin{tabular}{P{0.7 cm} P{0.9cm} P{1cm} P{2 cm} P{0.4cm} P{1.2cm} 
   P{0.4cm} P{0.8cm} P{0.5cm} P{0.9cm} }
  Ref & IL & H$\kappa$ & $D_{it}$ & $C_{ox}(\mu F/cm^2)$ & Technique & 
  $\sigma$ & Sn & Strain & Device \\
  \hline
  \cite{gong2012towards} & $SiO_2/Si$ & 3.6 nm Hf$O_2$ & $1.7 \times 10^{12}$(MG)   & 2.2   & CP & - & 3\% & F.S & p-FET \\
    \hline
  \end{tabular}
  \caption{No Caption} \label{table: No label}
\end{table}
0

3 Answers 3

6

I suggest you use a tabularx environment, to ensure that the material will fit inside the text block, with a centered version of the package's X column for 5 or the 10 columns, to allow automatic line-wrapping if needed. I would also like to suggest that you use the macros of the siunitx package to typeset units and numbers. Finally, do use the line-drawing macros of the booktabs package to obtain well-spaced lines.

enter image description here

\documentclass{article}
\usepackage{booktabs,ragged2e}
\usepackage{siunitx}
\sisetup{tight-spacing = true, per-mode = symbol}
\usepackage{tabularx}
\newcolumntype{C}{>{\Centering\arraybackslash}X}

\begin{document}
\begin{table}
  \small  % \scriptsize not needed anymore
  \begin{tabularx}{\textwidth}{@{} c *{5}{C} *{4}{c} @{}}
  Ref & IL & H$\kappa$ & $D_{it}$ & 
  $C_{ox}$ (\si{\micro\farad\per\centi\meter\squared}) & 
  \hspace{0pt}Technique & $\sigma$ & Sn & Strain & Device \\
  \midrule
  \cite{gong2012towards} & $SiO_2/Si$ & 
  \SI{3.6}{\nano\meter} Hf$O_2$ & \num{1.7e12} (MG)   & 
  2.2   & CP & -- & 3\% & F.S & p-FET \\
  \bottomrule
  \end{tabularx}
  \caption{No Caption} 
  \label{table:NoLabel}
\end{table}
\end{document}

Addendum, posted after the OP left a comment that line-breaks weren't acceptable. If linebreaks aren't acceptable, and if you're not willing to switch to an extremely small font size (which, in my view, you shouldn't do anyway), the main option that's left is to switch to a landscape-oriented table. The following example employs a sidewaystable environment, and it uses a tabular* environment instead of a tabularx environment, as automatic text wrapping isn't supposed to happen.

enter image description here

\documentclass{article}
\usepackage{booktabs,mhchem,rotating,siunitx}
\sisetup{tight-spacing = true, per-mode = symbol}

\begin{document}
\begin{sidewaystable}
\setlength\tabcolsep{0pt} % make LaTeX figure out intercolumn whitespace
  \begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l *{9}{c} }
  Ref & IL & H$\kappa$ & $D_{it}$ & 
  $C_{ox}$ (\si{\micro\farad\per\centi\meter\squared}) & 
  Technique & $\sigma$ & Sn & Strain & Device \\
  \midrule
  \cite{gong2012towards} & \ce{SiO2}/\ce{Si} & 
  \SI{3.6}{\nano\meter} \ce{HfO2} & \num{1.7e12} (MG)   & 
  2.2 & CP & -- & 3\% & F.S & p-FET \\
  \bottomrule
  \end{tabular*}
  \caption{No Caption} 
  \label{table:NoLabel}
\end{sidewaystable}
\end{document}
4
  • Hi Mico, in your version, I like that the table fits my text block. However, I see that technique coloum also breaks - which I do not want. is there a way out ?
    – Rouge
    Commented Aug 27, 2017 at 12:24
  • @Rouge - You have the choice between two not-so-great options: (a) allow line breaks, and use a font size that's readable, and (b) disallow line breaks, and switch to a tiny font that likely nobody will be able to read. When facing this trade-off, I'd choose the first option... A third option, I suppose, would be to see if you really, truly do need all ten columns. Any chance you could get by with "only" [!] 6 or 7 columns? :-)
    – Mico
    Commented Aug 27, 2017 at 12:57
  • @Rouge - A fourth option, I suppose, would be to switch the table's orientation to landscape mode. Obviously, I'm not in a position to judge this option's overall visbility.
    – Mico
    Commented Aug 27, 2017 at 13:19
  • Thanks for your help. But I need all of the coloums and if the coloum breaks, the text inside it looks ugly. The text is readable but ofcourse it would be nice if I can somehow increase the size, but I don't see a possible way out. So my main concern at the moment is to fit the table in text block.
    – Rouge
    Commented Aug 27, 2017 at 13:30
3

A Solution using your code with minimal changes:

\documentclass{article}
\usepackage{array}

\begin{document}
   \begin{table}[h]
  \newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
  \setlength\extrarowheight{5pt}
  \scriptsize
  \centering
  \begin{tabular}{P{0.7 cm} P{0.9cm} P{1cm} P{2 cm} P{1.2cm} P{1.2cm} 
   P{0.4cm} P{0.8cm} P{0.5cm} P{0.9cm} }
  Ref & IL & H$\kappa$ & $D_{it}$ & $C_{ox}$ $(\mu F/cm^2)$ & Technique & 
  $\sigma$ & Sn & Strain & Device \\
  \hline
  \cite{gong2012towards} & $SiO_2/Si$ & 3.6 nm Hf$O_2$ & $1.7 \times 10^{12}$(MG)   & 2.2   & CP & - & 3\% & F.S & p-FET \\
    \hline
  \end{tabular}
  \caption{No Caption} \label{table: No label}
  \end{table}
\end{document}

Output: enter image description here

5
  • Is there any guarantee that the resulting table will fit inside the text block?
    – Mico
    Commented Aug 26, 2017 at 11:14
  • I added the solution just to show you your mistakes. the first one is that you was expecting that an inline math expression could be break automatically and this cant be done (You have to break manually). Also \centering is followed only if the width of the column you are giving in P type is greater or at least equal to the real width of the cell's content. (See H_k column that is close to centered but not exactly and Strain title that is righter than wanted). So you have to be careful and give the appropriate width in P type columns and you have to break math expressions manually.
    – koleygr
    Commented Aug 26, 2017 at 11:20
  • 1
    @Mico... No it is not... I just trying to show OP's mistakes to understand the problem and suggesting to him to chose your answer. Just thought it could help him understand the problem
    – koleygr
    Commented Aug 26, 2017 at 11:22
  • her not him :-)
    – Rouge
    Commented Aug 27, 2017 at 12:33
  • @Rouge - Sorry! :-)
    – Mico
    Commented Aug 27, 2017 at 12:58
2

Some improvements with booktabs (adds vertical padding to horizontal rules); makecell (allows line breaks in standard cells), siunitx (formatting of numbers/units) and chemformula since you seem to have some chemical formulae. The c column type is enough, without having to calculate column widths by error and trial, and I can use the \small fontsize, not scriptsize that no one will want to read:

\documentclass{article}
\usepackage[showframe]{geometry}
\usepackage{array, makecell, booktabs}
\usepackage{siunitx}
\DeclareSIUnit \uF { \micro \farad }
\usepackage{chemformula}


\begin{document}

\begin{table}[h]
  \newcolumntype{P}[1]{>{\centering\arraybackslash}p{#1}}
  \setlength\extrarowheight{5pt}
 \small% \footnotesize
  \centering
  \begin{tabular}{*{10}{c}}
  Ref & IL & H$\kappa$ & $D_\textrm{it}$ & \makecell{$C_\textrm{ox}$\\(\si{\uF/\cm^2})} & Technique &
  $\sigma$ & Sn & Strain & Device \\
  \midrule
  \cite{gong2012towards} & \ch{SiO2}/Si & \makecell{\SI{3.6}{nm}\\ \ch{HfO2}} & \num{1.7e12} (MG) & 2.2 & CP & --- & 3\,\% & F.S & p-FET \\
    \bottomrule
  \end{tabular}
  \caption{No Caption} \label{table: No label1}
\end{table}

\end{document} 

enter image description here

Added:

Playing with the value of tabcolsep, the follwing code fits between the margins in \small font size:

\begin{table}[!htb]
\setlength\tabcolsep{4pt}
\setlength\extrarowheight{5pt}
\small
\centering
\begin{tabular}{*{10}{c}}%{P{0.7 cm} P{0.9cm} P{1cm} P{2 cm} P{1.2cm} P{1.2cm}
       % P{0.2cm} P{0.3cm} P{0.8cm} P{0.9cm} }
\toprule
Ref & IL & H$\kappa$ & \makecell[t]{$D_\textrm{it}$\\(\si{\cm^{-2}\eV^{-1}})} &
\makecell[t]{$C_\textrm{ox}$\\(\si{\uF/\cm^2})} & Technique &
    $\sigma$ & Sn & Strain & Device \\
\midrule
{} [Gong12] %\cite{gong2012towards}
     & \ch{SiO2}/Si & \makecell{\SI{3.6}{nm}\\
    \ch{HfO2}} &\num{1.7e12}(MG) & 2.2 & CP & --- & 3\,\% & F.S & p--FET
    \\ %
{} [Lee14] %\cite{lee2014epitaxial}
  & \ch{SiO2} & \ch{Yb2O3} & $\sim{}$\num{4e11}(MG)
 & 5 & $G_p/\omega-\omega$ & --- & 5\,\% & \SI{-0.2}{\percent} & pMOS-CAP \\ %
 \bottomrule
\end{tabular}
\caption{No Caption} \label{table: No label}
\end{table}

enter image description here

10
  • Hi Bernard, thanks your answer helps me ease out a lot of other things too...However, with your code, the size of the table increases and it's extending into the margins (i.e if I dont specify the coloumn width) . is there a way to avoid it ?
    – Rouge
    Commented Aug 27, 2017 at 11:57
  • With this very code? Perhaps you don't load geometry? The default margins are very large, because LaTeX supposes you have marginal notes. If you don't use them, just loading geometry makes the margins more sensible. Other than that, one can change the font size to \footnotesize (not less, or no one will read the table), or play the value of \tabcolsep (6pt by default, you can go down to 3pt without any problem) or you can use the adjustwidth environment. Could you post a typical example?
    – Bernard
    Commented Aug 27, 2017 at 12:25
  • Also I get no error when I use chemformula package. However, I see \ch{} appears as a unrecognized command (it get's highlighted). How do I solve it ? Thanks for your help.
    – Rouge
    Commented Aug 27, 2017 at 12:32
  • What do you mean with ‘\ch {}` gets heighlighted’? Highlighted in the editor, or in the .log file?
    – Bernard
    Commented Aug 27, 2017 at 12:56
  • Yes I don't use geomtry. Because when I use it, I get an error: Option clash for package geometry. \usepackage . I am not able to get rid of this error.
    – Rouge
    Commented Aug 27, 2017 at 13:05

You must log in to answer this question.

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