1

i tried to build this table using latex, i don't know what's wrong. What i want

\setlength\LTleft{0pt}
\setlength\LTright{0pt}
\begin{longtable}{@{\extracolsep{\fill}}|[c]@{}}


 \hline
 \multicolumn{2}{| r |}{\cellcolor{gray!25} Begin of Table}\\
 \hline
 A) Something & B) something j\\
  \hline
  C) Something & D) something j\\
 \hline
 \endfirsthead



 \hline
 \endfoot


 \endlastfoot

 \end{longtable}
  • welcome to tex.se! do you really need longtable? is many page long? from table image is seems that tabular* or tabularx can be is sufficient. – Zarko Dec 15 '17 at 8:22
  • Your code doesn't compile: You set up the longtable as having a single column, yet you then have a \multicolumn{2}{..}{...} directive. Please make the code compilable -- so that it actually generates the error you're looking to fix. – Mico Dec 15 '17 at 8:37
2

it is not clear, which table you like to obtain. if the first one, and if the table on the end will longer than one page, than solution can be:

\documentclass{article}
\usepackage{geometry}
\usepackage[table]{xcolor}
\usepackage{longtable, tabularx}

%-------------------------------- show page layout, only for test
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    with \verb+longtable+:
\begin{longtable}{|*{2}{p{\dimexpr0.5\linewidth-2\tabcolsep-\arrayrulewidth\relax}|}}
    \hline
\multicolumn{2}{| c |}{\cellcolor{gray!25} Begin of Table}\\
    \hline
 A) Something   & B) something j    \\
    \hline
 C) Something & D) something j\\
    \hline
    \end{longtable}

with \verb+tabularx+:
    \begin{center}
\begin{tabularx}{\linewidth}{|X|c|X|c|}
    \hline
    \rowcolor{gray!25}
\multicolumn{4}{| l |}{What is capital of Canada?}  \\
    \hline
Berlin   & C &  Ottawa  & A    \\
    \hline
Rome    & D &  Canberra & B    \\
    \hline
\end{tabularx}
    \end{center}
\end{document}

giving

enter image description here

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.