1

I have created two tables but I can't make them look as I desire, and also they are larger than the page margins so they aren't even centered. I want them to look like the pictures attached, but can’t make it work. Well the first table I think is relatively ok, just only I would like to center it, and if there is any way that I could center the content of an entire column? The second table has given me more trouble.

image 1

enter image description here

Table 1:

\begin{table}[htb]
\centering
\begin{tabular}{|l|l|l|l|}
\hline
\multirow{5}{2cm}{Casos Aceptables} & Casos & N\'umero de tarjetas & Porcentaje\\ \cline{2-4}
& \'Optimos & 49 & 49\% \\ \cline{2-4}
& Errores atribuibles al OCR & 9 & 9\%\\ \cline{2-4}
& Errores atribuibles a la tarjeta & 15 & 15\%\\ \cline{2-4}
& Total & 73 & 73\% \\ \cline{2-4} \hline
Casos no aceptables & No Aceptables & 27 & 27\% \\ \cline{1-4}
& Total & 100 & 100\% \\ \cline{2-4} \hline
\end{tabular}
\caption{Tabla 1.}
\label{tabla:final}
\end{table}

Table 2:

\begin{table}[htb]
\centering
\begin{tabular}{|l|l|l|l|}
\hline
\multirow{4}{2cm}{Casos Aceptables} & Casos & Error en caracteres & Tipo de Error\\ \cline{2-4}
& \'Optimos & Error menor al 4\% & Caracteres \\ \cline{2-4}
& Errores atribuibles al OCR & Error menor al 8\% & Caracteres\\ \cline{2-4}
& Errores atribuibles a la tarjeta & Error menor al 5\% & Caracteres e informaci\'on en los campos \\ \cline{2-4}
\hline
\end{tabular}
\caption{Tabla 2.}
\label{tabla:final}
\end{table}
3
  • I think the first table is also too wide so it is spilling into the right margin, that's why it doesn't look centred. You need to either shrink your margins, or shrink your table, it's that simple. However it's also clear that some of your cells should have line breaks in them. The most basic way of doing this is to specify p{width} as your column specifier and choose an appropriate width. Other solutions such as the tabularx package are available.
    – Au101
    Commented Mar 14, 2016 at 3:52
  • You should really check out the tables section of a good introductory guide
    – Au101
    Commented Mar 14, 2016 at 3:52
  • Somebody will hurt me for saying this, but one way you can center your table on the page without messing with the margins or the table is to wrap the whole thing in a centerline, like so \begin{table}\centerline{\begin{tabular}{cccc}\hline etc\end{tabular}}\end{table} But you might be better off using a side ways table or something. Anyway, to center a column, just use c instead of l in the column spec.
    – Mark
    Commented Mar 14, 2016 at 4:16

3 Answers 3

0

Code for my solution

\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{table}[htb]
\centering
\begin{tabular}{|l|l|l|l|}
\hline
\multirow{5}{2cm}{Casos Aceptables} & Casos & N\'umero de tarjetas & Porcentaje\\ \cline{2-4}
& \'Optimos & 49 & 49\% \\ \cline{2-4}
& Errores atribuibles al OCR & 9 & 9\%\\ \cline{2-4}
& Errores atribuibles a la tarjeta & 15 & 15\%\\ \cline{2-4}
& Total & 73 & 73\% \\ \cline{2-4} \hline
Casos no aceptables & No Aceptables & 27 & 27\% \\ \cline{1-4}
& Total & 100 & 100\% \\ \cline{2-4} \hline
\end{tabular}
\caption{Tabla 1.}
\label{tabla:final}
\end{table}
\begin{table}[htb]
 \centering
\begin{tabular}{|l |p{3.2cm}|p{3cm}|p{3.2cm}|}
\hline
\multirow{4}{*}{Casos Aceptables} & Casos & Error en caracteres & Tipo de Error\\ \cline{2-4}
& \'Optimos & Error menor al 4\% & Caracteres \\ \cline{2-4}
 & Errores atribuibles al OCR & Error menor al 8\% & Caracteres\\ \cline{2-4}
& Errores atribuibles a la tarjeta & Error menor al 5\% & Caracteres e informaci\'on en los campos \\ \cline{2-4}
\hline
\end{tabular}
 \caption{Tabla 2.}
\label{tabla:final}
\end{table}
\end{document}
1
  • 2
    Can you merge the two parts of your answer into one (1) posting?
    – DG'
    Commented Mar 14, 2016 at 9:49
2

Both tables are too wide to fit fully inside the text block.

To fix this problem, I suggest you employ tabularx environments instead of tabular environments for both tables. The tabularx environment provides a column type named X for automatic wrapping of a cell's contents. Set the width of both tabularx environments to \textwidth. For the first table, I use a modified (viz., centered) form of the X column type for columns 3 and 4 in the code shown below. For the second table, one could use another modified (viz., ragged-right) form of X for columns 2, 3, and 4.

I would further like to suggest that you (a) provide a lot more visual structure to the respective headers and left-hand columns of the tables and (b) also give the tables a more "open" look. To generate such a look, get rid of all vertical bars (trust me: they won't be missed) and most horizontal bars, and use the line-drawing macros of the booktabs package -- \toprule, \midrule, \cmidrule, and \bottomrule -- for the remaining horizontal lines.

enter image description here

\documentclass{article}
\usepackage[spanish]{babel}
\usepackage{booktabs,tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\begin{document}
\begin{table}[ht!]
\setlength\tabcolsep{5pt} % default: 6-py
\begin{tabularx}{\textwidth}{@{}llCC@{}}
\toprule
& Casos & N\'umero de tarjetas & Porcentaje\\ 
\cmidrule(l){2-4}
Casos aceptables & \'Optimos & 49 & 49\% \\ 
& Errores atribuibles al OCR & 9 & 9\%\\ 
& Errores atribuibles a la tarjeta & 15 & 15\%\\ 
& Total & 73 & 73\% \\  
\addlinespace
Casos no aceptables & No Aceptables & 27 & 27\% \\ 
\addlinespace
Total & & 100 & 100\% \\ 
\bottomrule
\end{tabularx}
\caption{Tabla 1.}
\label{tabla:final}
\end{table}

\begin{table}[h!]
\setlength\tabcolsep{4pt} % default: 6pt
\begin{tabularx}{\textwidth}{@{}lLLL@{}}
\toprule
 & Casos & Error en caracteres & Tipo de Error\\ 
\cmidrule(l){2-4}
Casos Aceptables
& \'Optimos & Error $<$ 4\% & Caracteres \\ 
& Errores atribuibles al OCR & Error $<$ 8\% & Caracteres\\ 
& Errores atribuibles a la tarjeta & Error $<$ 5\% & Caracteres e informaci\'on en los campos \\ 
\bottomrule
\end{tabularx}
\caption{Tabla 2.}
\label{tabla:final}
\end{table}
\end{document}
0

In the second table use\begin{tabular}{|l |p{3.2cm}|p{3cm}|p{3.2cm}|} and compile. You will get what you want. [cortbl[1]

1
  • Please also post the code that goes along with the screenshot.
    – Mico
    Commented Mar 14, 2016 at 6:40

You must log in to answer this question.

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