TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have the following code:

\begin{tabularx}{1\textwidth}{|c||p{4cm}||p{3cm}|}
\hline
\textsc{\textbf{Nombre}} & \textsc{\textbf{Ancho de banda con compresión}} & \textsc{\textbf{Ancho de banda sin compresion}} \\ \hline
H.261 & 40 Kbits/s & 2 Mbits/s \\ \hline
H.263 & 64 Kbits/s & 583.9 Mbits/s \\ \hline
H.263p & 64 Kbits/s & 583.9 Mbits/s \\ \hline
H.264 & 64 Kbits/s & 960 Mbit/s \\ \hline
\end{tabularx}

My problem is that I don't know why it give me this output: latex

Why the yellow zone appears?

Thanks in advance.

share|improve this question
1  
set one column X – touhami Feb 2 at 13:14
    
The tabularx tries to fill the whole width, regardless whether there are columns or not. (And as touhami said: use X for at least one column) – Christian Hupfer Feb 2 at 13:15
    
Off-topic: There is no bold-smallcaps font combination in the Computer Modern font family; that's why the screenshot is showing bold rather than bold-smallcaps glyphs in the header row. If you must have the bold-smallcaps combination, you will need to use a different font family, such as Times Roman. – Mico Feb 2 at 13:29
    
There really is no point to using tabularx there it is designed to adjust linebreaking and you never want automatic linebreaking in data tables, just use a normal tabular – David Carlisle Feb 2 at 13:31
    
@DavidCarlisle - There's line-breaking going on in two of the header cells. :-) – Mico Feb 2 at 13:33

I can't understand why you use \tabularx if you than not use X column type ... If you like to have table width equal to \textwidth, than exploit tabularx capabilities!

Anyway, see if the following solutions is what you looking for:

enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}
\usepackage{newtxtext,newtxmath}

    \usepackage{makecell,tabularx}
    \renewcommand\theadfont{\bfseries\scshape}
    \usepackage{siunitx}

    \begin{document}
\begin{tabularx}{\textwidth}{|X||X||S[table-format=3.2]@{}X<{Mbits/s}|}
                                    \hline
\thead{Nombre} 
        & \thead{Ancho de banda\\ con compresión} 
                     & \multicolumn{2}{c|}{
                       \thead{Ancho de banda\\ sin compresion}} 
                               \\   \hline
H.261   & 40 Kbits/s &   2   & \\   \hline
H.263   & 64 Kbits/s & 583.9 & \\   \hline
H.263p  & 64 Kbits/s & 583.9 & \\   \hline
H.264   & 64 Kbits/s & 960   & \\   \hline
\end{tabularx}
    \end{document}

In it I stole font issues from Mico answer, employ makecell package for seting column headers and for numbers in the third column use S columns from siunitx.

Alternative solution, as rswponse to Mico comment:

enter image description here

In this case the code is a bit modified:

\documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage[spanish]{babel}
    \usepackage{newtxtext,newtxmath}

    \usepackage{makecell,tabularx}
    \renewcommand\theadfont{\bfseries\scshape}
    \usepackage{siunitx}

    \begin{document}
\begin{tabularx}{\textwidth}{|@{\quad}l||
           >{\centering\arraybackslash}X||S[table-format=9.2]@{}l<{Mbits/s\qquad\qquad}|}
                                    \hline
\thead{Nombre}
        & \thead{Ancho de banda\\ con compresión}
                     & \multicolumn{2}{c|}{
                       \thead{Ancho de banda\\ sin compresion}}
                               \\   \hline
H.261   & 40 Kbits/s &   2   & \\   \hline
H.263   & 64 Kbits/s & 583.9 & \\   \hline
H.263p  & 64 Kbits/s & 583.9 & \\   \hline
H.264   & 64 Kbits/s & 960   & \\   \hline
\end{tabularx}
    \end{document}
share|improve this answer
    
Thanks, this works also – Onemikoscar Feb 2 at 15:39
    
If you're going to center-set the material in the header row, I think the material in the data columns should be center-set as ewll (rather than be set (mostly) flush-left). – Mico Feb 2 at 15:42
    
@Mico, you have right. To my answer I added example as you suggest. – Zarko Feb 2 at 16:24

You ask for a tabular length of \textwidth but do not adpate the size of the column. You could use X to do so. In tabularx, X will expand the column to fit the required size.

For example:

\documentclass{article}
\usepackage{tabularx}
\begin{document}

\begin{tabularx}{1\textwidth}{|X||p{4cm}||p{3cm}|}
\hline
\textsc{\textbf{Nombre}} & \textsc{\textbf{Ancho de banda con compresión}} & \textsc{\textbf{Ancho de banda sin compresion}} \\ \hline
H.261 & 40 Kbits/s & 2 Mbits/s \\ \hline
H.263 & 64 Kbits/s & 583.9 Mbits/s \\ \hline
H.263p & 64 Kbits/s & 583.9 Mbits/s \\ \hline
H.264 & 64 Kbits/s & 960 Mbit/s \\ \hline
\end{tabularx}
\end{document}

Output:

enter image description here

share|improve this answer
1  
The X instead of c is better for two reasons: alignment and of course using tabularx features (+1) – Christian Hupfer Feb 2 at 13:20
    
Thanks you, this works for me :D – Onemikoscar Feb 2 at 15:32

In addition to providing at least one type-X column in a tabularx environment, you should also

  • use a font family that actually provides bold-smallcaps glyphs (Computer Modern does not), and

  • not use full justification in narrow columns, as doing so will almost certainly create unacceptably large gaps between words; instead, use ragged-right mode in narrow columns

  • strive for a more "open" look of the table, by (i) not using any vertical bars, (ii) getting rid of the majority of horizontal lines, and (iii) using the line-drawing macros of the booktabs package for the remaining few horizontal lines.

enter image description here

\documentclass{article}
\usepackage{tabularx}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[spanish]{babel}

% Use a font family that provides bold&smallcaps glyphs
\usepackage{newtxtext,newtxmath}     
\usepackage{booktabs,ragged2e}

% ragged-right version of "p" column type
\newcolumntype{P}[1]{>{\RaggedRight\arraybackslash}p{#1}} 

\begin{document}
\noindent
\begin{tabularx}{1\textwidth}{X P{3cm} P{3cm}}
\toprule
\textsc{\textbf{Nombre}} & 
\textsc{\textbf{Ancho de banda con compresión}} & 
\textsc{\textbf{Ancho de banda sin compresión}} \\
\midrule
H.261 & 40 Kbits/s & 2 Mbits/s \\ 
H.263 & 64 Kbits/s & 583.9 Mbits/s \\ 
H.263p & 64 Kbits/s & 583.9 Mbits/s \\ 
H.264 & 64 Kbits/s & 960 Mbit/s \\ 
\bottomrule
\end{tabularx}
\end{document} 
share|improve this answer
    
Thanks you, this works. I will put in use all of your advices. – Onemikoscar Feb 2 at 15:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.