-1

I am trying to generate a table with tablegenerator.com that looks like this(the latex commands should be processed by LaTex) enter image description here

The code which is produces by the site is:

\begin{table}[]
\centering
\begin{tabular}{|c|c|}
\hline
\multicolumn{1}{|l|}{\textbf{Channel}} & \textbf{Background sample name} \\ \hline
ggH & \begin{tabular}[c]{@{}c@{}}\textsf{mc15\_13TeV.341000.PowhegPythia8EvtGen\_CT10\_AZNLOCTEQ6L1\\ \_ggH125\_gamgam.merge.AOD.e3806\_s2984\_r8585\_r7676}\end{tabular} \\ \hline
VBF & \begin{tabular}[c]{@{}c@{}}\textsf{mc15\_13TeV.341001.PowhegPythia8EvtGen\_CT10\_AZNLOCTEQ6L1\\ \_VBFH125\_gamgam.merge.AOD.e3806\_s2608\_r7772\_r7676}\end{tabular} \\ \hline
ZH & \begin{tabular}[c]{@{}c@{}}\textsf{mc15\_13TeV.341068.Pythia8EvtGen\_A14NNPDF23LO\\ \_ZH125\_gamgam.merge.AOD.e3796\_s2608\_s2183\_r7772\_r7676}\end{tabular} \\ \hline
WH & \begin{tabular}[c]{@{}c@{}}\textsf{mc15\_13TeV.341067.Pythia8EvtGen\_A14NNPDF23LO\\ \_WH125\_gamgam.merge.AOD.e3796\_s2608\_s2183\_r7772\_r7676}\end{tabular} \\ \hline
ttH & \begin{tabular}[c]{@{}c@{}}\textsf{mc15\_13TeV:mc15\_13TeV.341081.aMcAtNloHerwigppEvtGen\_UEEE5\\ \_CTEQ6L1\_CT10ME\_ttH125\_gamgam.merge.AOD.e4277\_s2608\_s2183\_r7772\_r7676}\end{tabular} \\ \hline
\end{tabular}
\caption{My caption}
\label{my-label}
\end{table}

However, Latex complains when I insert it in my file with missing } and extra } errors. The problem seems only to occur when I make a new line inside of the row (because text is to large) Does anyone have an idea what causes this issue and how to solve it?

Cheers

Mark
  • 214
  • Maybe: https://tex.stackexchange.com/questions/485 (How to break a line in a table [duplicate]) or https://tex.stackexchange.com/questions/2441 (How to add a forced line break inside a table cell). – Dr. Manuel Kuehner Jun 20 '17 at 20:38
  • Your image looks like it has raw LaTeX code in it, while your code doesn't appear to be trying to do that. Are you trying to have the table entries be the output of those commands? – Teepeemm Jun 20 '17 at 20:40
  • @Teepeemm I dont know exactly what you mean, but the latex code is processed fine without the line break. – Mark Jun 20 '17 at 20:44
  • your question says you want the table to look like the image but that shows \textsf{... Do you really want that verbatim latex command in the final result or do you want the result of that command, which would be a sans serif font selection? – David Carlisle Jun 20 '17 at 20:51
  • @DavidCarlisle I want the result of that command ;) – Mark Jun 20 '17 at 20:52
  • well then please fix your question which does not ask for that at all so is terribly misleading – David Carlisle Jun 20 '17 at 20:54
  • 2
    this seems a very simple table of two columns of plain text, why not simply right in in latex rather than writing it in some table generator that generates latex code that is vastly more complicated than needed, which you then have to fix? – David Carlisle Jun 20 '17 at 20:56

3 Answers3

0

I think your problem is actually that you have text split across 2 lines, and you are trying to change the font for both lines with one command. If instead, you encase each line in it's own \textsf command, it should work. My code looks like this:

\documentclass{article}
\begin{document}


\begin{table}
\centering
\begin{tabular}{|c|c|}
\hline
\multicolumn{1}{|l|}{\textbf{Channel}} & \textbf{Background sample name} \\ \hline
ggH & \begin{tabular}[c]{@{}c@{}}\textsf{mc15\_13TeV.341000.PowhegPythia8EvtGen\_CT10\_AZNLOCTEQ6L1}\\ \textsf{\_ggH125\_gamgam.merge.AOD.e3806\_s2984\_r8585\_r7676}\end{tabular} \\ \hline
VBF & \begin{tabular}[c]{@{}c@{}}\textsf{mc15\_13TeV.341001.PowhegPythia8EvtGen\_CT10\_AZNLOCTEQ6L1}\\ \textsf{\_VBFH125\_gamgam.merge.AOD.e3806\_s2608\_r7772\_r7676}\end{tabular} \\ \hline
ZH & \begin{tabular}[c]{@{}c@{}}\textsf{mc15\_13TeV.341068.Pythia8EvtGen\_A14NNPDF23LO}\\ \textsf{\_ZH125\_gamgam.merge.AOD.e3796\_s2608\_s2183\_r7772\_r7676}\end{tabular} \\ \hline
WH & \begin{tabular}[c]{@{}c@{}}\textsf{mc15\_13TeV.341067.Pythia8EvtGen\_A14NNPDF23LO}\\ \textsf{\_WH125\_gamgam.merge.AOD.e3796\_s2608\_s2183\_r7772\_r7676}\end{tabular} \\ \hline
ttH & \begin{tabular}[c]{@{}c@{}}\textsf{mc15\_13TeV:mc15\_13TeV.341081.aMcAtNloHerwigppEvtGen\_UEEE5}\\ \textsf{\_CTEQ6L1\_CT10ME\_ttH125\_gamgam.merge.AOD.e4277\_s2608\_s2183\_r7772\_r7676}\end{tabular} \\ \hline
\end{tabular}
\caption{My caption}
\label{my-label}
\end{table}

\end{document}

And the output looks like this: enter image description here

0

What you are trying to typeset looks a little bit like filenames, so why not ask LaTeX to take the filenames without having to escape underscores and have them break nicely across lines. This can be automated using tabularx. We also give a little more room between rows.

\documentclass{article}

\usepackage{booktabs}

\usepackage{tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}
\renewcommand{\tabularxcolumn}[1]{m{#1}}

\usepackage{url}
\DeclareUrlCommand\filename{\urlstyle{sf}}

\begin{document}

\begin{table}
  \renewcommand\arraystretch{1.5}
  \begin{tabularx}{\textwidth}{@{}cC@{}}
    \toprule
    \textbf{Channel} & \multicolumn{1}{c}{\textbf{Background sample name}}                                                                                        \\
    \midrule
    ggH              & \filename{mc15_13TeV.341000.PowhegPythia8EvtGen_CT10_AZNLOCTEQ6L1 _ggH125_gamgam.merge.AOD.e3806_s2984_r8585_r7676}                        \\
    VBF              & \filename{mc15_13TeV.341001.PowhegPythia8EvtGen_CT10_AZNLOCTEQ6L1 _VBFH125_gamgam.merge.AOD.e3806_s2608_r7772_r7676}                       \\
    ZH               & \filename{mc15_13TeV.341068.Pythia8EvtGen_A14NNPDF23LO _ZH125_gamgam.merge.AOD.e3796_s2608_s2183_r7772_r7676}                              \\
    WH               & \filename{mc15_13TeV.341067.Pythia8EvtGen_A14NNPDF23LO _WH125_gamgam.merge.AOD.e3796_s2608_s2183_r7772_r7676}                              \\
    ttH              & \filename{mc15_13TeV:mc15_13TeV.341081.aMcAtNloHerwigppEvtGen_UEEE5 _CTEQ6L1_CT10ME_ttH125_gamgam.merge.AOD.e4277_s2608_s2183_r7772_r7676} \\
    \bottomrule
  \end{tabularx}
  \caption{My caption}
  \label{my-label}
\end{table}

\end{document}

enter image description here

Henri Menke
  • 109,596
-1

solution

Since all latex commands and environments begin with a slash, writing slashes inside texts can be problematic. To solve this problem use verbatim package along with \verb|<text>| command which allows for taking the text exactly as it is. However, the package verbatim is not compatible with tabular environment and you will need. In your case, the use of verbatim package inside a table would mean that your long lines in the second column would extend beyond the text range. To solve this problem, you will need to use multirow package so that you can split the codes above into multiple lines. The code that generates the result above is as follows:

\documentclass{report}
\usepackage{verbatim}
\usepackage{multirow}
\usepackage{booktabs}
\begin{document}


\begin{table*}[]
    \centering
    \begin{tabular}[1\textwidth]{|c|c|}



    \hline
    \multicolumn{1}{|l|}{\textbf{Channel}} & \textbf{Background sample name}
    \\
    \hline



    \multirow{2}{*}{ggH} &
    \verb|[c]{@{}c@{}}\textsf{mc15\_13TeV.341000.PowhegPythia8EvtGen\_CT10|
    \\

    & \verb|\_AZNLOCTEQ6L1\\\_ggH125\_gamgam.merge.AOD.e3806\_s2984\_r8585\_r7676}|
    \\
    \hline



    \multirow{2}{*}{VBF} & \verb|[c]{@{}c@{}}\textsf{mc15\_13TeV.341001.PowhegPythia8EvtGen\_CT10|
    \\

    & \verb|\_AZNLOCTEQ6L1\\ \_VBFH125\_gamgam.merge.AOD.e3806\_s2608\_r7772\_r7676}|
    \\
    \hline



    \multirow{2}{*}{ZH}
    & \verb|[c]{@{}c@{}}\textsf{mc15\_13TeV.341068.Pythia8EvtGen\_A14NNPDF23LO|
    \\

    & \verb|\\ \_ZH125\_gamgam.merge.AOD.e3796\_s2608\_s2183\_r7772\_r7676}|
    \\
    \hline



    \multirow{2}{*}{WH}
    & \verb|[c]{@{}c@{}}\textsf{mc15\_13TeV.341067.Pythia8EvtGen\_A14NNPDF23LO\\ |
    \\

    & \verb|\_WH125\_gamgam.merge.AOD.e3796\_s2608\_s2183\_r7772\_r7676}|
    \\
    \hline



    \multirow{3}{*}{ttH}
    & \verb|[c]{@{}c@{}}\textsf{mc15\_13TeV:mc15\_13TeV.341081.|
    \\

    & \verb|aMcAtNloHerwigppEvtGen\_UEEE\_CTEQ6L1\_CT10ME\_ttH125|
    \\

    & \verb|\_gamgam.merge.AOD.e4277\_s2608\_s2183\_r7772\_r7676}|
    \\
    \hline


\end{tabular}
\caption{My caption}
\label{my-label}
\end{table*}

\end{document}

You can make the table even smaller by splitting the code into three lines like in the last entry in the table.

  • Thank you for your answer, but I actually want the LaTex code to be processsed, i.e. LaTex should only show mc15_13TeV.341000.PowhegPythia8EvtGen_CT10_AZNLOCTEQ6L1_ggH125_gamgam.merge.AOD.e3806_s2984_r8585_r7676, with the textsf style applied, for instance. How do I do this? – Mark Jun 21 '17 at 18:35