3

I am trying to build a table using longtable and tabularx with the ltxtable. For some weird reason, unwanted vertical lines appear on the first row. This is my main.tex:

\documentclass[12pt,twoside]{report}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{longtable}
\usepackage{ltxtable}
\begin{document}
  \LTXtable{\linewidth}{table.tex}
\end{document}

This is table.tex:

\small
\begin{longtable}{| p{0.7cm} | X |}\label{tab:evaluation_survey}
\\ \hline
\multirow{2}{*}{e.1)} &  \textbf{Question}:\\
\cline{2-2}
& \textbf{Answers}: \\ \hline
\hline
\multirow{2}{*}{e.2)} &  \textbf{Question}: \\
\cline{2-2} 
& \textbf{Answers}:  \\ \hline
\hline
\multirow{2}{*}{e.3)} &  \textbf{Question}: \\ 
\cline{2-2} 
& \textbf{Answers}: \\ \hline
\hline
\multirow{2}{*}{e.4)} &  \textbf{Question}:\\ 
\cline{2-2} 
& \textbf{Answers}: \\ \hline
\end{longtable}

And this is what appears: enter image description here

Edit: if I remove the \\ before the first \hline I receive \noalign and \omit errors

4
  • 7
    Welcome to TeX SX! Remove the first \\ before \hline.
    – Bernard
    Commented Mar 21, 2017 at 10:47
  • Welcome to TeX.SE! Please merge bot code snippets into complete document, which we can copy and compile.
    – Zarko
    Commented Mar 21, 2017 at 10:48
  • @Zarko: ltxtable needs the table in an extra file. So the document is complete with the two files. The user could use filecontents to generate it from main.tex. Or you could copy both files. But you cannot replace \LTXtable{…}{…} by the code from table.tex. Commented Mar 21, 2017 at 11:18
  • @Schweinebacke, ups, I overlooked ltxtable ...
    – Zarko
    Commented Mar 21, 2017 at 11:24

2 Answers 2

1

The problem arises from the usage of \label{} inside the table. Normally you use \label{} after the caption in the floating environment. I don't know LTXtable so I can't provide the correct placement for the \label{} but just to solve the issue there are several ways here (like placing the \label{} inside one of the existing rows etc.). One of this ways would be to use a \noalign{}:

Change the content of table.tex to:

\small
\begin{longtable}{| p{0.7cm} | X |}\noalign{\label{tab:evaluation_survey}}
\hline
\multirow{2}{*}{e.1)} &  \textbf{Question}:\\
\cline{2-2}
& \textbf{Answers}: \\ \hline
\hline
\multirow{2}{*}{e.2)} &  \textbf{Question}: \\
\cline{2-2} 
& \textbf{Answers}:  \\ \hline
\hline
\multirow{2}{*}{e.3)} &  \textbf{Question}: \\ 
\cline{2-2} 
& \textbf{Answers}: \\ \hline
\hline
\multirow{2}{*}{e.4)} &  \textbf{Question}:\\ 
\cline{2-2} 
& \textbf{Answers}: \\ \hline
\end{longtable}
1

I suggest this code, based on ltablex, which brings the functionalities of longtable to tabularx. I also redesigned the table, based on hhline and makecell so the cells do not look as tight as the default.

\documentclass{article}

\usepackage{multirow, ltablex, hhline, makecell}
\keepXColumns
\setcellgapes{1ex}

\begin{document}

\small\setlength\doublerulesep{2ex}%
\makegapedcells
\begin{tabularx}{\linewidth}{@{}p{0.7cm} |X|}
\caption{A questions and answers table}\label{tab:evaluation_survey}\\[-1ex]
\endfirsthead
\hhline{~|-}
\multirow{2}{=}{e.1)} & \textbf{Question}:\\%
\hhline{~|-}
& \textbf{Answers}: \\
\hhline{~:=}
\multirow{2}{=}{e.2)} & \textbf{Question}: \\
\hhline{~|-}
& \textbf{Answers}: \\
\hhline{~:=}
\multirow{2}{=}{e.3)} & \textbf{Question}: \\
\hhline{~|-}
& \textbf{Answers}: \\
\hhline{~:=}
\multirow{2}{=}{e.4)} & \textbf{Question}:\\
\hhline{~|-}
& \textbf{Answers}: \\
\hhline{~|-}
\end{tabularx}

\end{document} 

enter image description here

You must log in to answer this question.

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