3

I am a complete beginner in Latex. I wanted to create a table. Unfortunately it was a bit crowded and it did not fit into the page. So, I wanted to decrease font size inside the table and googled it. I found [this][1] answer and applied it. It helped me to fit the table into the page but now, I cannot add caption to my table. Whenever I try to add it I got the following error:

You can't use `\hrule' here except with leaders. \caption@hrule ->\hrule \@height \z@ l.203 \end{tabular}}

Here is the code I use to create the table:

\begin{table}
\resizebox{\textwidth}{!}{%
\centering
\captionsetup{labelformat=empty}
\caption{Data statistics Treebanks. The values on \{Train,Dev,Test\}-Set columns are the number of tokens in the splits. Unique tags column gives the number of distinct sets of tags (pos + morphological features) assigned to words, unique features gives the number of distinct features that exist in the dataset.}
\begin{tabular}{llllll|llllll}
\multicolumn{1}{c}{\textbf{lang}} & \multicolumn{1}{c}{\textbf{train}} & \multicolumn{1}{c}{\textbf{dev}} & \multicolumn{1}{c}{\textbf{test}} & \multicolumn{1}{c}{\textbf{\textbar{}T\textbar{}}} & \multicolumn{1}{c|}{\textbf{\textbar{}F\textbar{}}} & \multicolumn{1}{c}{\textbf{lang}} & \multicolumn{1}{c}{\textbf{train}} & \multicolumn{1}{c}{\textbf{dev}} & \multicolumn{1}{c}{\textbf{test}} & \multicolumn{1}{c}{\textbf{\textbar{}T\textbar{}}} & \multicolumn{1}{c}{\textbf{\textbar{}F\textbar{}}}  \\ 
\hline
ar                                & 1                                  & 4                                & 2                                 & 123                                                & 123123                                              & es                                & 123                                & 902                              & 123                               & 234                                                & 31567                                               \\
bg                                & 3425                               & 45                               & 234                               & 5252                                               & 1231634                                             & pt                                & 755                                & 234                              & 645                               & 2464                                               & 242                                                 \\
cs                                & 767                                & 23                               & 86                                & 345453                                             & 23422                                               & sk                                & 3453                               & 1231                             & 235                               & 43243                                              & 34663                                               \\
en                                &                                    &                                  &                                   &                                                    &                                                     & sl                                &                                    &                                  &                                   &                                                    &                                                     \\
et                                &                                    &                                  &                                   &                                                    &                                                     & ru                                &                                    &                                  &                                   &                                                    &                                                     \\
fr                                &                                    &                                  &                                   &                                                    &                                                     & hi                                &                                    &                                  &                                   &                                                    &                                                     \\
hu                                &                                    &                                  &                                   &                                                    &                                                     & lv                                &                                    &                                  &                                   &                                                    &                                                     \\
ro                                &                                    &                                  &                                   &                                                    &                                                     & nl                                &                                    &                                  &                                   &                                                    &                                                     \\
tr                                &                                    &                                  &                                   &                                                    &                                                     & pl                                &                                    &                                  &                                   &                                                    &                                                     \\
hr                                &                                    &                                  &                                   &                                                    &                                                     & de                                &                                    &                                  &                                   &                                                    &                                                     \\
it                                &                                    &                                  &                                   &                                                    &                                                     & gr                                &                                    &                                  &                                   &                                                    &                                                     \\
da                                &                                    &                                  &                                   &                                                    &                                                     & la                                &                                    &                                  &                                   &                                                    &                                                     \\
ca                                &                                    &                                  &                                   &                                                    &                                                     & ko                                &                                    &                                  &                                   &                                                    &                                                     \\
fi                                &                                    &                                  &                                   &                                                    &                                                     & ir                                &                                    &                                  &                                   &                                                    &                                                    
\end{tabular}}
\end{table}

The packages I am using:

\usepackage{booktabs}
\usepackage{float}
\usepackage{breakcites}
\usepackage{svg}
\usepackage{graphics}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{caption}

If I comment the \captionsetup and \caption lines, table appears without caption

3
  • 2
    Welcome to TeX.SX! Try moving the lines with caption out of the resizebox. Btw: Using resizebox is almost always a bad choice.
    – TeXnician
    Commented Apr 14, 2018 at 8:40
  • @TeXnician thank you so much! It works. Do you have any alternative? I use it because it is the only option I could find.
    – zwlayer
    Commented Apr 14, 2018 at 8:42
  • 1
    See also tex.stackexchange.com/questions/332902/…
    – TeXnician
    Commented Apr 14, 2018 at 8:47

3 Answers 3

4

Don't use resizebox unless you're willing to let the font size in the table be wildly different from what's in use in the surrounding text.

Some additional suggestions:

  • Use the \small font size directive (for a 10% linear font size reduction) and employ a tabular* environment, rather than a tabular environment, to typeset the table material.

  • Since you're loading the booktabs package anyway, do make use of its macros: \toprule, \bottomrule, and \cmidrule.

  • Keep the table's caption short and snappy. If you have a longer legend, place it between the caption and the table.

  • Right-aligning the 10 numeric columns would seem preferable to left-aligning them.

  • Writing $|\mathbf{T}|$ is easier than \textbf{\textbar{}T\textbar{}}, right?

Here's the output of the MWE that implements these ideas.

enter image description here

\documentclass{article}
\usepackage{booktabs,caption}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\begin{document}
\begin{table}
\captionsetup{font=small,skip=0.333\baselineskip}
\caption*{Data statistics Treebanks}

\small
The values in the \{Train, Dev, Test\}-Set of columns 
are the number of tokens in the splits. Unique tags 
column gives the number of distinct sets of tags 
(pos~+ morphological features) assigned to words, 
unique features gives the number of distinct features 
that exist in the dataset.

\medskip
\setlength\tabcolsep{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}
    *{2}{l*{5}{r}}}
\toprule
\textbf{lang} & \mc{\textbf{train}} & \mc{\textbf{dev}} 
  & \mc{\textbf{test}} & \mc{$|\mathbf{T}|$} & \mc{$|\mathbf{F}|$} &
\textbf{lang} & \mc{\textbf{train}} & \mc{\textbf{dev}} 
  & \mc{\textbf{test}} & \mc{$|\mathbf{T}|$} & \mc{$|\mathbf{F}|$} \\
\cmidrule{1-6} \cmidrule{7-12} 
ar & 1   & 4 & 2  & 123 & 123123 &
es & 123 & 902 & 123  & 234 & 31567  \\
bg & 3425  & 45  & 234  & 5252  & 1231634 &
pt & 755 & 234 & 645  & 2464  & 242  \\
cs & 767 & 23  & 86 & 345453 & 23422 &
sk & 3453  & 1231 & 235  & 43243 & 34663  \\
en &     &   &    &     &     & 
sl &     &   &    &     &      \\
et &     &   &    &     &     & 
ru &     &   &    &     &      \\
fr &     &   &    &     &     & 
hi &     &   &    &     &      \\
hu &     &   &    &     &     & 
lv &     &   &    &     &      \\
ro &     &   &    &     &     & 
nl &     &   &    &     &      \\
tr &     &   &    &     &     & 
pl &     &   &    &     &      \\
hr &     &   &    &     &     & 
de &     &   &    &     &      \\
it &     &   &    &     &     & 
gr &     &   &    &     &      \\
da &     &   &    &     &     & 
la &     &   &    &     &      \\
ca &     &   &    &     &     & 
ko &     &   &    &     &      \\
fi &     &   &    &     &     & 
ir &     &   &    &     &     \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}
4
  • I have edited my question. Could you help me about it ?
    – zwlayer
    Commented Apr 14, 2018 at 10:27
  • @zwlayer - You should have posted a new query, rather than severely modify the initial form of the query. Please consider (a) reverting the existing query to its initial query and (b) posting a separate, new query with the new table.
    – Mico
    Commented Apr 14, 2018 at 10:36
  • 1
    I did your suggestion. Here is the link for new query: tex.stackexchange.com/q/426510/160757
    – zwlayer
    Commented Apr 14, 2018 at 10:39
  • I edit my question. You can find it here: tex.stackexchange.com/q/434027/160757
    – zwlayer
    Commented May 29, 2018 at 19:59
2

You should not use \resizebox for tables, as it leads to inconsistent fontsizes, and often unreadable tables. Here is a solution with a simple change of the fontsize in the table environment, and a smaller value of \tabcolsep, which is the padding on both sides of a column. I also took the liberty to slightly change the layout of the table:

\documentclass{article}
\usepackage[utf8]{inputenc} 
\usepackage[T1]{fontenc}
\usepackage{array}
\usepackage{caption}

\begin{document}

\begin{table}
\centering\small\setlength{\tabcolsep}{3.6pt}
\setlength{\extrarowheight}{2pt}
\captionsetup{labelformat=empty, font = small}
\caption{Data statistics Treebanks. The values on \{Train,Dev,Test\}-Set columns are the number of tokens in the splits. Unique tags column gives the number of distinct sets of tags (pos + morphological features) assigned to words, unique features gives the number of distinct features that exist in the dataset.}
\begin{tabular}{@{}c*{5}{l}|c*{5}{l}@{}}
\multicolumn{1}{c}{\textbf{lang}} & \multicolumn{1}{c}{\textbf{train}} & \multicolumn{1}{c}{\textbf{dev}} & \multicolumn{1}{c}{\textbf{test}} & \multicolumn{1}{c}{\textbf{\textbar{}T\textbar{}}} & \multicolumn{1}{c|}{\textbf{\textbar{}F\textbar{}}} & \multicolumn{1}{c}{\textbf{lang}} & \multicolumn{1}{c}{\textbf{train}} & \multicolumn{1}{c}{\textbf{dev}} & \multicolumn{1}{c}{\textbf{test}} & \multicolumn{1}{c}{\textbf{\textbar{}T\textbar{}}} & \multicolumn{1}{c}{\textbf{\textbar{}F\textbar{}}} \\
\hline
ar & 1 & 4 & 2 & 123 & 123123 & es & 123 & 902 & 123 & 234 & 31567 \\
bg & 3425 & 45 & 234 & 5252 & 1231634 & pt & 755 & 234 & 645 & 2464 & 242 \\
cs & 767 & 23 & 86 & 345453 & 23422 & sk & 3453 & 1231 & 235 & 43243 & 34663 \\
en & & & & & & sl & & & & & \\
et & & & & & & ru & & & & & \\
fr & & & & & & hi & & & & & \\
hu & & & & & & lv & & & & & \\
ro & & & & & & nl & & & & & \\
tr & & & & & & pl & & & & & \\
hr & & & & & & de & & & & & \\
it & & & & & & gr & & & & & \\
da & & & & & & la & & & & & \\
ca & & & & & & ko & & & & & \\
fi & & & & & & ir & & & & &
\end{tabular}%}
\end{table}

\end{document} 

enter image description here

1

One can simplify the input by nesting tabular* environments.

The values for table-format can be adjusted post-facto when the complete data is visible.

\documentclass{article}
\usepackage{booktabs,caption,siunitx}

\begin{document}

\begin{table}
\caption{Data statistics Treebanks}

The values in the \{Train, Dev, Test\}-Set of columns 
are the number of tokens in the splits. Unique tags 
column gives the number of distinct sets of tags 
(pos~+ morphological features) assigned to words, 
unique features gives the number of distinct features 
that exist in the dataset.

\medskip

\small

\setlength{\tabcolsep}{0pt} % let tabular* do the job

\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}ll@{}}
\toprule
\begin{tabular*}{.48\textwidth}[t]{
  @{\extracolsep{\fill}}
  l
  S[table-format=4.0]
  S[table-format=4.0]
  S[table-format=3.0]
  S[table-format=6.0]
  S[table-format=7.0]
  @{}
}
\textbf{lang} & {\textbf{train}} & {\textbf{dev}} 
  & {\textbf{test}} & {$|\mathbf{T}|$} & {$|\mathbf{F}|$} \\
\midrule
ar & 1   & 4 & 2  & 123 & 123123 \\
bg & 3425  & 45  & 234  & 5252  & 1231634 \\
cs & 767 & 23  & 86 & 345453 & 23422 \\
en &     &   &    &     &     \\
et &     &   &    &     &     \\
fr &     &   &    &     &     \\
hu &     &   &    &     &     \\ 
ro &     &   &    &     &     \\
tr &     &   &    &     &     \\
hr &     &   &    &     &     \\
it &     &   &    &     &     \\
da &     &   &    &     &     \\
ca &     &   &    &     &     \\
fi &     &   &    &     &     \\
\end{tabular*}
&
\begin{tabular*}{.48\textwidth}[t]{
  @{\extracolsep{\fill}}
  l
  S[table-format=4.0]
  S[table-format=4.0]
  S[table-format=3.0]
  S[table-format=6.0]
  S[table-format=7.0]
  @{}
}
\textbf{lang} & {\textbf{train}} & {\textbf{dev}} 
  & {\textbf{test}} & {$|\mathbf{T}|$} & {$|\mathbf{F}|$} \\
\midrule
es & 123 & 902 & 123  & 234 & 31567  \\
pt & 755 & 234 & 645  & 2464  & 242  \\
sk & 3453  & 1231 & 235  & 43243 & 34663  \\
sl &     &   &    &     &      \\
ru &     &   &    &     &      \\
hi &     &   &    &     &      \\
lv &     &   &    &     &      \\
nl &     &   &    &     &      \\
pl &     &   &    &     &      \\
de &     &   &    &     &      \\
gr &     &   &    &     &      \\
la &     &   &    &     &      \\
ko &     &   &    &     &      \\
ir &     &   &    &     &     \\
\end{tabular*} \\
\bottomrule
\end{tabular*}

\end{table}

\end{document}

enter image description here

You must log in to answer this question.

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