Here are some more to add on Phil and Werner's answer: first, for list structure, you should consider using enumerate
environment; second, even with tabularx
LaTeX will still have some trouble handling extremely long word which had appeared in your example, in this case you can either use \hyphenation{...}
to manually set up hyphenation or use \seqsplit{...}
provided by seqsplit
package. Now here is a demonstration:
\usepackage{seqsplit}
Here I skip the preamble for it's too long
\begin{questions}
\titledquestion{Match the Pairs}[10]
\noindent
\begin{tabularx}{\linewidth}{XX}
\hline
\hline
A
\begin{enumerate}
\renewcommand{\labelenumi}{\arabic{enumi})}
\item Why this text is dummy over here
\item THis is one word
\item This is dummy value al dfadf adf adfasdf \ ddfakdfaasdf .
\item asd fads adsfkaj dkladjsflkadsf asdfa skdlj, asdfasdasdfasdfa
\item asdfasdfjas;dlfkjaslkdalkdsjf;alksdjfasdklfads
\end{enumerate}
&
B
\begin{enumerate}
\renewcommand{\labelenumi}{\alph{enumi})}
\item there is not dummy text
\item THis is not the correct word
\item values are here for all fasdf ad asdfasdkfad.
\item adjfklasd fasldfjasdlkfjasdlkfadsflkja sdflkjasd;lfkjasd;lfkja;sldkfjals;dk
\item
\seqsplit{adjfklasdjfa;lksdjf;alskdjf;alskdjf;alksdjf;laksdjf;alksdfj;alksdfja;lksdfja;lksdfja;lskdfj;alksdjfalksdfjasdklfjas;dlfja;sdlkfalkdjfa;lkdsjf;alksdfaldfja;lsdkfja;lsdkjf;alskdfj;aldkjf;alksdjfalksddddddfajsdlkfja;lsdkjf ;alsdjf ;asdjf; ajdf;l j;asdlfj ;alkdjsf;laksejriaeidkl ja;dlkfja;slkdfj a;ldskfja;sdikdfka dof asdf asdfk;lajsd;flkaj d;lkfajsd;lfk ja;dsfj ;alskdjf; lkadsjf;alksdjf; alsdfkja;lskdjf;alsdjf;alsdkjf;alskdjf}
\end{enumerate}
\\
\hline
\end{tabularx}
and its result:
Update
After thinking a while about your new request I came up a way to mimic the enumerate
environment with tabularx
. First of all, we need to define two new counters:
\newcounter{counterA}
\setcounter{counterA}{0}
\newcounter{counterB}
\setcounter{counterB}{0}
Then we need two new column types:
\newcolumntype{A}{
@{
\stepcounter{counterA}
\hspace{\itemindent}
\arabic{counterA})
\hspace{\labelsep}
\vspace{\itemsep}
}X}
\newcolumntype{B}{
@{
\stepcounter{counterB}
\hspace{\itemindent}
\alph{counterA})
\hspace{\labelsep}
\vspace{\itemsep}
}X}
Now let's check out the code (again this is only the crucial part):
\begin{questions}
\titledquestion{Match the Pairs}[10]
\begin{tabularx}{\linewidth}{AB}
\hline
\hline
\multicolumn{2}{l}{A\hspace{216.46775pt}B}\\[\topsep]
Why this text is dummy over here &
there is not dummy text\\
THis is one word &
THis is not the correct word \\
This is dummy value al dfadf adf adfasdf \ ddfakdfaasdf . &
values are here for all fasdf ad asdfasdkfad.\\
asd fads adsfkaj dkladjsflkadsf asdfa skdlj, asdfasdasdfasdfa &
adjfklasd fasldfjasdlkfjasdlkfadsflkja sdflkjasd;lfkjasd;lfkja;sldkfjals;dk\\
asdfasdfjas;dlfkjaslkdalkdsjf;alksdjfasdklfads &
\seqsplit{adjfklasdjfa;lksdjf;alskdjf;alskdjf;alksdjf;laksdjf;alksdfj;alksdfja;lksdfja;lksdfja;lskdfj;alksdjfalksdfjasdklfjas;dlfja;sdlkfalkdjfa;lkdsjf;alksdfaldfja;lsdkfja;lsdkjf;alskdfj;aldkjf;alksdjfalksddddddfajsdlkfja;lsdkjf ;alsdjf ;asdjf; ajdf;l j;asdlfj ;alkdjsf;laksejriaeidkl ja;dlkfja;slkdfj a;ldskfja;sdikdfka dof asdf asdfk;lajsd;flkaj d;lkfajsd;lfk ja;dsfj ;alskdjf; lkadsjf;alksdjf; alsdfkja;lskdjf;alsdjf;alsdkjf;alskdjf}\\
\hline
\end{tabularx}
\end{questions}
that will give us:
As you can see, what we got is quite similar to the implemented enumerate
environment we previously have, and this time we also have nice vertical alignment. However, this method still has some imperfections, for instances:
- There are some mysterious indentation caused by
seqsplit
I don't quite understand.
- In the first line of the table,
\topsep
is from the list
environment. I tried to put it into column definition with \ifnum
but failed :P
216.46775pt
is manually calculated 0.5\linewidth-\columnsep
, I don't know how to make calc
work inside a table so I didn't use it.
et cetera et cetera.
This is exactly the same problem I and my classmates were having when writing our lab reports on Experimental Physics. Since we work in groups it's great to have data on the cloud. The problem was converting sometimes dozens of tables to Latex...
So, I and a classmate of mine came up with LatexKit, a google sheets add-on that creates and exports to your Google Drive a text file containing the tabular environment of a given table.
For your case, this won't handle page width or height, nor copy the exact borders you have configured (although there is a way to overcome this, keep reading), but it can help you get started with little trouble and systematically for multiple tables.
This add-on is developed using Google apps script so, unfortunately, the lack of some features is not easily overcomeable.
It does, however, help a lot when converting tables from Google Sheets to Latex
It has some additional features that could help you or someone else in the future.
Current Features:
Features that can or will be implemented (given the time and will of the community):
- Configure the table to have the same alignments as in your Spreadsheet
- Handle different font styles like bold, italic, etc...
- And a lot more, you just have to pitch us the idea! Reach us either trough facebook or e-mail: latexkit.dev@gmail.com
Here's LatexKit in action
This is the table on the spreadsheet:
This is the exact code produced by LatexKit using the template 'grid':
\begin{tabular}{|c|c|}
\hline
Time (h) & Temperature (C) \\ \hline
12 & 19.5 $\pm$ 0.4 \\ \hline
13 & 20.3 $\pm$ 0.6 \\ \hline
14 & 21.8 $\pm$ 0.7 \\ \hline
15 & 20.9 $\pm$ 0.6 \\ \hline
16 & 19.7 $\pm$ 0.4 \\ \hline
\end{tabular}
This is the result when compiled in Latex:
This is really a project to the community so we would gladly take your advice to improve!
Best Answer
It's straightforward to create such a table using the
xcolor
andcolortbl
packages. You didn't indicate the preferred width of the table, so I've assumed it should be as wide as the text block.Addendum -- As @barbarabeeton has pointed out in a comment, the horizontal lines in the preceding table are spaced very narrowly and created a cramped look. One way to improve the table's look is to insert (typographic) struts. Insert a "top" strut if there's an
\hline
immediately ahead of the material, insert a "bottom" strut if there's an\hline
immediately after the material, and insert both a top and a bottom strut if the material is in a header row. (For more on typographic struts in a LaTeX document see, e.g., https://tex.stackexchange.com/a/50355/5001.)