2

After see the Andrew Swann solution to my previous question: How to fit this table in a page? I tried to fit it to another table:

\documentclass[11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[spanish,mexico]{babel}
\usepackage[T1]{fontenc}
\usepackage{booktabs,longtable}
\usepackage{array}

\begin{document}

{\small\setlength\tabcolsep{5pt}
\begin{tabularx}{\linewidth}{ll*{2}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}}
\caption{Temario de actividades Secundaria} \\
\toprule
\textsc{Horario} & \textsc{Ejercicio} & \textsc{Grado de riesgo} & \textsc{Material}\\
\addlinespace[0.5ex]
\toprule
\addlinespace[2ex]
\endfirsthead
\multicolumn{4}{c}{\textsc{\tablename~\thetable}\enspace (continuación)}\\
\addlinespace[2ex]
\toprule
\textsc{Horario} & \textsc{Ejercicio} & \textsc{Grado de riesgo} & \textsc{Material}\\
\addlinespace[0.5ex]
\toprule
\endhead
\midrule
\multicolumn{4}{r}{Continúa}
\endfoot
\bottomrule
\endlastfoot
    {\normalsize Día 1} & Bienvenida Encuadre Tema:Acuerdos de convivencia Ejercicios psicométricos & 1 & Pelota de esponja \emph{Brincón} Ejercicios psicométricos. Guía Eureka (Ver Anexo)\\
 \addlinespace
     {\normalsize Día 2} & Ejercicios psicométricos & 0 & Ejercicios psicométricos. Guía Eureka\\
\addlinespace
    {\normalsize Día 3} & Ejercicios psicométricos & 0 & Ejercicios psicométricos\\
\addlinespace
    {\normalsize Día 4} & Examen simulacro de ejercicios psicométricos en equipo & 0 & Ejercicios psicométricos. Guía verde actualizada 2000 (Ver Anexo).\\
\addlinespace
    {\normalsize Día 5} & EXAMEN DE CONOCIMIENTOS GENERALES & & \\
\end{tabularx}
}
\end{document}

Well, that's the table I need to do, but I'm not sure how to do it well. My first doubt is about the column statement, from my previous question and other solutions I saw I adapted this:

\begin{tabularx}{\linewidth}{ll*{3}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}}

As I need 5 columns, I understand that the table has 3 left aligned columns, later another not justified (RaggedRight) and a final X column, am I right? But I'm not sure about it. The code in ll*{3}{>{\RaggedRight\arraybackslash\hspace{0pt}}X} is hard to understand for me, could someone explain me?


Update

After the comments and the answer I made few corrections in the table, I saw that a a column had not sense. But the layout of the table is awful. How can I fix it? Is there a way to list or separate the text in a cell if I need a list and not a paragraph?

3
  • Your MWE still doesn't work. see my answer and correct your MWE accordingly. which column haven't sense? Table as I show is relative narrow. I do not have idea about width of linewidth in your document. It will look better if you select smaller font or replace caps letter with ordinary and if you can make wider line width.
    – Zarko
    Commented Oct 5, 2014 at 1:24
  • @Zarko Check my comment and last version of the MNWE. Commented Oct 5, 2014 at 1:26
  • @Zarko Thanks for you solution, this makes easier to create the tables I need, I like it. Commented Oct 5, 2014 at 2:15

3 Answers 3

6
ll*{3}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}

is

ll

two columns of single line left aligned entries, then

 *{3}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}

three copies of >{\RaggedRight\arraybackslash\hspace{0pt}}X

each of these is basically an X column which is p{...} for an automatically calculated width.

The tokens in the >{...} are applied to the start of each cell. In this case that is

\RaggedRight\arraybackslash\hspace{0pt}

\RaggedRight is an improved version of \raggedright from the ragged2e package.

\arraybackslash is defined in tabularx it redefines \\ to end the table row (which is its normal definitions in tabular, but \ragedright, \RaggedRight etc redefine it locally to make a ragged text line end, which is not wanted here.

Starting a paragraph with \hspace{0pt} is an old trick to put a space before the first word which allows TeX to hyphenate the first word in the paragraph. (TeX's hyphenation algorithm otherwise doesn't consider the first word, which is probably a bug really but TeX is frozen and isn't going to change that behaviour.

7
  • What does \addlinespace? It creates an empty line for all the columns or just for the first cell? Commented Oct 4, 2014 at 18:36
  • 1
    @IraultzaBelaustegigoitia it's a booktabs command, try texdoc booktabs and look at page 5, apparently it adds space it is equivalent to the standard \\[...] which adds extra space after th eline as well. Commented Oct 4, 2014 at 18:56
  • So, if I have a table with odd number of columns, instead of use \begin{tabularx}{\linewidth}{ll*{3}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}} for 6 columns, should I do \begin{tabularx}{\linewidth}{l*{5}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}}, is it correct? Commented Oct 4, 2014 at 19:31
  • 1
    @IraultzaBelaustegigoitia yes if you want the last 5 columns to be the same the *{3}{..} syntax is just a macro expanded first |*{3}{c|} is same as |c|c|c| and is literally expanded to that before the main tabular code starts. Commented Oct 4, 2014 at 19:53
  • 1
    @IraultzaBelaustegigoitia The table in mwe has 2 l columns and 3 X , your suggested replacement had 1 l and 5 X but you can have whatever number you want If you want lXclXc then you can have that, I'm not sure what you are asking/ Commented Oct 4, 2014 at 20:19
1

David Carlisle already answered to your first questions. So I will try to help you to resolve in other problems. Your MWE has some errors like \caption is after \begin{tabularx} ..., it hasn't \end{document}. And the most notable, to me it is not clear if you like to have longtabe (spread over more page) or just simple table in float environment. I assume that last one is the case and remake your MWE in the following:

    \documentclass[11pt]{book}
\usepackage[utf8]{inputenc}
%\usepackage[spanish,mexico]{babel} i haven't it ..
\usepackage[T1]{fontenc}
\usepackage{ragged2e}
\usepackage{booktabs,tabularx}

    \usepackage[labelsep=colon,
                labelfont={bf},
                justification=raggedright, 
                singlelinecheck=false]{caption}% added for caption custumization

%% just for shoving test result, erase this two line in final text
\usepackage[active,floats,tightpage]{preview}                                                              
\setlength\PreviewBorder{1em}

    \newcolumntype{C}{>{\centering\arraybackslash}X}
    \newcolumntype{L}{>{\RaggedRight\arraybackslash}X}

\begin{document}
    \begin{table}
    \setlength\tabcolsep{3pt}
    \small
\caption{Temario de actividades Secundaria}
    \begin{tabularx}{\linewidth}{
        c% first column, I change "l" to "c" (matter of taste)
        >{\setlength\hsize{1.2\hsize}}L% I make it wider
        c% third column, I change it from X to c; Is it really necessary since it is empty?,
          % does it should has equal width as second and last column?      
        >{\setlength\hsize{.6\hsize}}C% I make it narrower
        >{\setlength\hsize{1.2\hsize}}L% I make it wider
                                 }
    \toprule
Horario % I remove \textsc, for better looking of table 
        &   Ejercicio
            &   Objetivo
                &   Grado de riesgo
                    & Material                                      \\
    \midrule    
    Día 1
        & Bienvenida Encuadre Tema: Acuerdos de convivencia Ejercicios psicométricos
            &   &   1
                    &   Pelota de esponja \emph{Brincón} Ejercicios psicométricos.
                        Guía Eureka (Ver Anexo)                     \\
\addlinespace
    Día 2
        & Ejercicios psicométricos
            &   &   0
                    &   Ejercicios psicométricos. Guía Eureka       \\
\addlinespace
    Día 3
        &   Ejercicios psicométricos
            &   &   0
                    &   Ejercicios psicométricos                    \\
\addlinespace
    Día 4
        &   Examen simulacro de ejercicios psicométricos en equipo
            &   &   0
                    &   Ejercicios psicométricos.
                        Guía verde actualizada 2000 (Ver Anexo).    \\
\addlinespace
    Día 5
        &   Examen de conocimientos generales, gute
            &   &   &   \textbullet\    emulation of itemize 
                                        environment (to show 
                                        possible solutions)  \newline 
                        \textbullet\    second item \newline                                             \textbullet\    third item                  \\
    \bottomrule
    \end{tabularx}
    \end{table}
\end{document}

In the code I added some comments by which I try to clarify what I doing and what is beside mentioned not clear to me. As you can see, the table is put in table environment, and I also suggest to define new column type in document preamble. enter image description here

Edit: Iraultza Bellaustegigoitia, when you start with design of tables -- this is one of the most challenging task in use of LaTeX -- you need to take some decision as:

  • will table fit in one page or it is so big, that will be broken on more pages
  • can table float in text or not
  • should table has prescribed width

Considering answers to above question, you select tabular environment, for example tabularx for table on one page, longtable for bigger. etc. If you are not familiar with selected package, read (at least briefly) documentation, which is accompanied with package.

In design of table consider some simple rules:

  • newer mix particular features of different package (for example, use header/footer definition from longtable in tabularx). Exceptions are array and booktabs package, which are designed to support other tabular packages.
  • it is bad idea to use different font sizes in table

I redesign my MWE a bit, added example for simple emulating of lists in table cell (for more demanding layout I suggest to use some list packages as enumitem) and add a new picture of table generating by it. I hope that it is close to this, what you like to achieve and that this my addition will help to you.

1
  • Thanks for your answer, you're right, David answered my original question. About the errors in the MWE (actually MNWE), the omission of the \end{document} was a mistake in the last edition of the code I did. In the other hand, this table is not the only one in the document, I have other tables that uses a similar design with longtable that I try to use here, then the case was the one that you didn't choose. This table will grow in the next stage and will take at least two pages, now is short yet. Commented Oct 5, 2014 at 1:25
0

Well after struggling all damn day with this table, and thanks to the kind responses and explanations of David Carlisle and the Zarco trick, I have the table just as I wanted.

What I did was the following:

\documentclass[11pt]{book}
\usepackage[utf8]{inputenc}
\usepackage[spanish,mexico]{babel}
\usepackage[T1]{fontenc}

\usepackage{ragged2e}
\usepackage{array,caption}
\captionsetup{labelfont=sc,textfont=it}
\usepackage{tikz}
\usepackage{ltablex}
\renewcommand{\tabularxcolumn}[1]{>{\small}m{#1}}
\usepackage{multirow}
\usepackage{booktabs}
\usepackage{longtable}

\newcolumntype{C}{>{\centering\arraybackslash\hspace{0pt}}X}
\newcolumntype{L}{>{\RaggedRight\arraybackslash\hspace{0pt}}X}    

\begin{document}
{\small\setlength\tabcolsep{5pt}
\begin{tabularx}{\linewidth}{cLCL} % {lc*{2}L}
\caption{Temario de actividades Secundaria} \\
\toprule
\textsc{Horario} & \textsc{Ejercicio} & \textsc{Grado de riesgo} & \textsc{Material}\\
\addlinespace[0.5ex]
\toprule
\addlinespace[2ex]
\endfirsthead
\multicolumn{4}{c}{\textsc{\tablename~\thetable}\enspace (continuación)}\\
\addlinespace[2ex]
\toprule
\textsc{Horario} & \textsc{Ejercicio} & \textsc{Grado de riesgo} & \textsc{Material}\\
\addlinespace[0.5ex]
\toprule
\endhead
\midrule
\multicolumn{4}{r}{Continúa}
\endfoot
\bottomrule
\endlastfoot
    {\normalsize Día 1} & Bienvenida\par Encuadre\par Tema:\par Acuerdos de convivencia\par Ejercicios psicométricos & 1 & Pelota de esponja\par \emph{Brincón}\par Ejercicios psicométricos\par Guía Eureka (Ver Anexo)\\
 \addlinespace
     {\normalsize Día 2} & Ejercicios psicométricos & 0 & Ejercicios psicométricos. Guía Eureka\\
\addlinespace
    {\normalsize Día 3} & Ejercicios psicométricos & 0 & Ejercicios psicométricos\\
\addlinespace
    {\normalsize Día 4} & Examen simulacro de ejercicios psicométricos en equipo & 0 & Ejercicios psicométricos. Guía verde actualizada 2000 (Ver Anexo).\\
\addlinespace
    {\normalsize Día 5} & \multicolumn{3}{c}{EXAMEN DE CONOCIMIENTOS GENERALES} \\
 \addlinespace
    {\normalsize Día 6} & Autoconcepto \par Autoestima \par Elaboración de mi propio regalo & 2 & Papel bond\par Plumones\par Pegamento\par Tijeras\par Crayolas \\
\end{tabularx}
}
\end{document}

My other problem was how to enlist the text within a cell in this table. I don't think using an environment like itemize or enumerate nested inside was a good idea, that is, I don't think it compile correctly. Many times it's easy to separate the text using \\ but as in the tables is the way the lines are distinguished, neither seemed to work. In the end I tried to use \par and it worked, but I don't know if there is any better way.

2
  • 1
    I do not understand why you persist with declaration for first, second header/footer ... from longtable package in tabularx? This is worthless, distracting and not allowed! use different size of font also is not good idea. The caption should not be inside of tabularx ... and your last MWE doesn't work.
    – Zarko
    Commented Oct 6, 2014 at 4:26
  • @Zarko The MWE works, I revised it and now it works. I don't understand what is wrong with the table. Where should be the \caption? I put after tabularx because in a previous answer was there and it works, what's wrong? How should I use fonts if the size changes are bad? I used tabularx and longtable in another previous tables and works fine, why is too bad for you? Could you show me how to build right a table like this if I'm doing all so wrong? Commented Oct 6, 2014 at 19:25

You must log in to answer this question.

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