2

Sorry for this question but I'm new using LaTeX. I have a table which width is set to be \textwidth using tabularx{\textwidth} and one of its rows will have 3 or 4 lines. This is my current code:

\renewcommand{\arraystretch}{1.2}
    \arrayrulecolor{gray}
    \begin{table}[b!] % hbtp
        \centering
        \begin{tabularx}{\textwidth}{ c | c | X }
            \arrayrulecolor{black} 
            \hline
            \textbf{$e_\#$} & \textbf{Time interval} & \textbf{Topic} \\ 
            \hline
            \arrayrulecolor{gray}
            1 & \makecell{From: 2019-04-15 20:30:05 \\ To: 2019-04-15 21:30:05} & \textbf{díamundialdelarte, 15deabril:} enfocat(0.94), meningitis(0.94), construyendolarepública(0.94), 14deabril(0.68), ley(0.66), españa(0.62)  \\
            \hline
            2 & \makecell{From: 2019-04-15 09:00:05 \\ To: 2019-04-15 17:00:05} & \textbf{gracias:} semana(0.61), muchísimas(0.64) \\
            \hline
            3 & \makecell{From: 2019-04-15 19:30:05 \\ To: 2019-04-16 01:00:05} & \textbf{notre:} dame(0.98), catedral(0.92), incendio(0.76), parís(0.91), historia(0.73), humanidad(0.77), llamas(0.74), paris(0.64), tristeza(0.65)  \\
            \hline
        \end{tabularx}
        \caption{April 15th 2019 top 3 events}
        \label{tab:mabed-impact}
    \end{table}
    \arrayrulecolor{black}
    \renewcommand{\arraystretch}{1.5}

and this is its visualization:

Table visualization

I would like that:

  • All the cells were vertically centered
  • Columns 1 and 2 were horizontally centered
  • Column 3 were horizontally left aligned, but its header (row 1) were horizontally centered

How can achieve this?

UPDATE:

\begin{table}[hbtp]
        \centering
        \renewcommand{\tabularxcolumn}[1]{m{#1}}
        \begin{tabularx}{\textwidth}{ c c >{\RaggedRight}X }
            \toprule
            \textbf{$e_\#$} & \textbf{Time interval} & \makecell[cc]{\textbf{Topic}} \\ 
            \midrule
            1 & \begin{tabular}[t]{r@{:~}l} From & 2019-04-15 20:30:05 \\ To & 2019-04-15 21:30:05\end{tabular} & \textbf{díamundialdelarte, 15deabril:} enfocat(0.94), meningitis(0.94), construyendolarepública(0.94), 14deabril(0.68), ley(0.66), españa(0.62)  \\\addlinespace

            2 & \begin{tabular}[t]{r@{:~}l}From& 2019-04-15 09:00:05 \\ To & 2019-04-15 17:00:05\end{tabular} & \textbf{gracias:} semana(0.61), muchísimas(0.64) \\ \addlinespace
            3 & \begin{tabular}[t]{r@{:~}l}From & 2019-04-15 19:30:05 \\ To & 2019-04-16 01:00:05 \end{tabular} & \textbf{notre:} dame(0.98), catedral(0.92), incendio(0.76), parís(0.91), historia(0.73), humanidad(0.77), llamas(0.74), paris(0.64), tristeza(0.65)  \\
            \bottomrule
        \end{tabularx}
        \caption{April 15th 2019 top 3 events}
        \label{tab:mabed-impact}
    \end{table}

Update

1

You can redefine the tabularx X type column to be vertically centered using \renewcommand{\tabularxcolumn}[1]{m{#1}}. With the makecelll package that you already use, you can also change the horizontal (and vertical) alignment of a single cell. Combining these, you can achieve the following result:

enter image description here

\documentclass{article}
\usepackage{geometry}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage[table]{xcolor}
\usepackage{array}
\renewcommand{\tabularxcolumn}[1]{m{#1}}
\begin{document}


    \begin{table}
    \renewcommand{\arraystretch}{1.2}
    \arrayrulecolor{gray}
        \centering
        \begin{tabularx}{\textwidth}{ c | c | X }
            \arrayrulecolor{black} 
            \hline
            \textbf{$e_\#$} & \textbf{Time interval} & \makecell[cc]{\textbf{Topic}} \\ 
            \hline
            \arrayrulecolor{gray}
            1 & \makecell{From: 2019-04-15 20:30:05 \\ To: 2019-04-15 21:30:05} & \textbf{díamundialdelarte, 15deabril:} enfocat(0.94), meningitis(0.94), construyendolarepública(0.94), 14deabril(0.68), ley(0.66), españa(0.62)  \\
            \hline
            2 & \makecell{From: 2019-04-15 09:00:05 \\ To: 2019-04-15 17:00:05} & \textbf{gracias:} semana(0.61), muchísimas(0.64) \\
            \hline
            3 & \makecell{From: 2019-04-15 19:30:05 \\ To: 2019-04-16 01:00:05} & \textbf{notre:} dame(0.98), catedral(0.92), incendio(0.76), parís(0.91), historia(0.73), humanidad(0.77), llamas(0.74), paris(0.64), tristeza(0.65)  \\
            \hline
        \end{tabularx}
        \caption{April 15th 2019 top 3 events}
        \label{tab:mabed-impact}
    \end{table}


    \end{document}

Personally, I would suggest a slightly different design (less horizontal and no vertical lines, aligning th : in the second column):

enter image description here

\documentclass{article}
\usepackage{geometry}
\usepackage{tabularx}
\usepackage{makecell}
\usepackage{array}


\usepackage{booktabs}
\begin{document}

    \begin{table}
        \centering
        \begin{tabularx}{\textwidth}{ c  c  X }
            \toprule
            \textbf{$e_\#$} & \textbf{Time interval} & \makecell[cc]{\textbf{Topic}} \\ 
            \midrule
            1 & \begin{tabular}[t]{r@{:~}l} From & 2019-04-15 20:30:05 \\ To & 2019-04-15 21:30:05\end{tabular} & \textbf{díamundialdelarte, 15deabril:} enfocat(0.94), meningitis(0.94), construyendolarepública(0.94), 14deabril(0.68), ley(0.66), españa(0.62)  \\\addlinespace

            2 & \begin{tabular}[t]{r@{:~}l}From& 2019-04-15 09:00:05 \\ To & 2019-04-15 17:00:05\end{tabular} & \textbf{gracias:} semana(0.61), muchísimas(0.64) \\ \addlinespace
            3 & \begin{tabular}[t]{r@{:~}l}From & 2019-04-15 19:30:05 \\ To & 2019-04-16 01:00:05 \end{tabular} & \textbf{notre:} dame(0.98), catedral(0.92), incendio(0.76), parís(0.91), historia(0.73), humanidad(0.77), llamas(0.74), paris(0.64), tristeza(0.65)  \\
            \bottomrule
        \end{tabularx}
        \caption{April 15th 2019 top 3 events}
        \label{tab:mabed-impact}
    \end{table}


\end{document}

Lastly, some spaces seem to be missing in the text. Are díamundialdelarte and construyendolarepública really only one word?

  • Thanks for your reply. I really liked your proposal and I think I will implement it. Yes, words are the output of an event detector and those you quoted are hashtags used by users. – Luiscri May 18 at 17:42
  • @Luiscri: Thank you for the clarification. You might probabley be also interested in adding the ragged2e package and use \begin{tabularx}{\textwidth}{ c c >{\RaggedRight}X }. This way you can get rid of the large horizontal white spaces in the third column that originate from the text being justified. – leandriis May 18 at 17:46
  • Tried using your model but spaces between rows are too wide. Also spaces between 'From' and 'To' lines. Any idea what can be failing? – Luiscri May 18 at 17:51
  • @Luiscri: Did you redefine \arraystretch somewhere in the text of your document? This might cause the additional white space. – leandriis May 18 at 18:19
  • You were right, I had it set to 1.5 at some point on my code. However now col 1 and col 2 are aligned to the bottom of the row. How can I aling them to the top as you have it on your screenshot? – Luiscri May 18 at 18:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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