# How to use table in multicols env. with paragraphs p{} and \multicolumn as well?

updated question

I am going to start all over. Will make the question very simple and direct. Will leave the original question below.

I simply want to see an example of using \multicolumn in a table (any table env. will do) where the whole env. is typeset in a multicols.

Here is a MWE

\documentclass[english]{article}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{multirow}
\usepackage{array}
\usepackage{multicol}
\usepackage{babel}
\usepackage[pangram]{blindtext}
\usepackage{tabularx}

\begin{document}
\begin{multicols}{2}

\Blindtext[2][3]
\begin{tabularx}{.9\linewidth}{@{}|X|X|@{}}\hline
%\multicolumn{2}{c} \Blindtext[1][3]\\    %%  PROBLEM AREA HERE ******
\Blindtext[1][3]&\Blindtext[1][3]\\\hline
\end{tabularx}

\Blindtext[2][3]

\end{multicols}
\end{document}


If I un-comment the \multicolumn above, then the table does not typeset correctly. I need to use \multicolumn in the above. What do I need to do?

## old question

I'd like to use \multicols{3}, where 3 can be changed another value, without having to change the Latex code for setting up table in the code below that.

I'd like to use a table (tabular or tabular* or tabularx, whatever works). But use paragraph for columns of the table (or X if it works), since I want to put text that wraps automatically, or use enumeration lists and such, so it has to be paragraph, and I also want to use \multicolumn inside the table since I want to span one row over more than one column.

I found(*) that tabularx does not work well with \multicolumn. I also found if I use \multicolumn{2} things do not work, please see second example below. So there are some conflicts, and I am not able to find the correct combination to use.

If I use tabular, I have to use give explicit size for the column with using p{2in} or such. But I do not want to hardcode the width of the columns.

Nothing I tried worked. Here are my attempts

## Example 1

\documentclass[12pt,a4paper]{article}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{multirow}
\usepackage{array}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage{tabularx}

\begin{document}
\begin{multicols}{2}
\noindent

\lipsum[1]

%\begin{tabularx}{.8\textwidth}{@{}|X|X|@{}}
%\begin{tabularx}{.8\linewidth}{@{}|X|X|@{}}
%\begin{tabularx}{\hsize}{|X|X|}
%\begin{tabular*}{\hsize}{|l|p{.8\hsize}}}
%\begin{tabular*}{.8\textwidth}{|l|p{2in}}}
%\begin{tabular}{|p{1in}|p{2in}}
%\begin{tabular*}{.8\linewidth}{|p{.2\linewidth|p{.8\linewidth}}

\begin{tabularx}{.8\linewidth}{@{}|X|X|@{}}
\multicolumn{2}{c} The “lipsum” package is a more basic package.
It generates a certain  “lorem ipsum” text\\
The “lipsum” package is a more basic package. Itlorem ipsum” text&
The “lipsum” package is a more basic package. It generates a
certain number of the standard “lorem ipsum” text
\end{tabularx}
\lipsum[1]
\end{multicols}
\end{document}


## Example 2

removing \multicolumn{2}{c} seems to have helped.

\documentclass[12pt,a4paper]{article}
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{multirow}
\usepackage{array}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage{tabularx}

\begin{document}
\begin{multicols}{2}
\noindent

\lipsum[1]
%\begin{tabularx}{.8\textwidth}{@{}|X|X|@{}}
%\begin{tabularx}{.8\linewidth}{@{}|X|X|@{}}
%\begin{tabularx}{\hsize}{|X|X|}
%\begin{tabular*}{\hsize}{|l|p{.8\hsize}}}
%\begin{tabular*}{.8\textwidth}{|l|p{2in}}}
%\begin{tabular}{|p{1in}|p{2in}}
%\begin{tabular*}{.8\linewidth}{|p{.2\linewidth|p{.8\linewidth}}
%\begin{tabularx}{\columnwidth}{@{}|X|X|@{}}
\begin{tabularx}{.8\linewidth}{@{}|X|X|@{}}
%\multicolumn{2}{c} The “lipsum” package is a more basic package&
It generates a certain  “lorem ipsum” text\\
The “lipsum” package is a more basic package. Itlorem ipsum” text&
The “lipsum” package is a more basic package. It generates a
certain number of the standard “lorem ipsum” text
\end{tabularx}
\lipsum[1]
\end{multicols}
\end{document}


-
tabularx (and \multicolumn) have no connection to multicols I can't imagine why you say tabularx doesn't work with multicol it neither works with it or not work with it, it's simply unrelated. –  David Carlisle Dec 23 '13 at 11:23
@DavidCarlisle I meant to write it does not work well with \multicolumn, not multicols. I read this here "The way that tabularx calculates column widths isn't really compatible with the multicolumn" groups.google.com/forum/#!topic/comp.text.tex/WjdABHwT7-g but mixed multicols with multicolumn. Will fix now. –  Nasser Dec 23 '13 at 11:28

Your issues are not really related to multicol other than the fact that that changes the line width.

\noindent

...


\noindent followed by \par just makes a paragraph consisting of a blank line \parfillskip glue and no text so it will look a bit like spurious vertical space, except being a line box it will not be discarded at a page break, it will not prevent the indentation of the following text.

%\begin{tabularx}{.8\textwidth}{@{}|X|X|@{}}


This would make a table .8 of \textwidth which is much wider than the column (which is less that .5\textwidth, after you account for the column separation

%\begin{tabularx}{.8\linewidth}{@{}|X|X|@{}}


This would make a table .8 of the column width. It will be indented by \parindent and may or may not reach the right edge of the column, depending if \parindent is bigger or smaller than .2\linewidth

%\begin{tabularx}{\hsize}{|X|X|}


this makes a table the columnwidth (somewhat inefficiently as you know in advance you want both columns the same width, but TeX doesn't know that) The line will be overful due to the paragraph indentation.

%\begin{tabular*}{\hsize}{|l|p{.8\hsize}}}


If you use tabular* you need to use \extracolumsep to add some stretch otherwise you are specifying a target width and give Tex no way to achieve it. (Also you should use \linewidth not \hsize.)

%\begin{tabular*}{.8\textwidth}{|l|p{2in}}}


as above .8\textwidth is too wide and you have not supplied any way to stretch the table.

%\begin{tabular}{|p{1in}|p{2in}}


This will make a table of the specified width, indented by parindent

%\begin{tabular*}{.8\linewidth}{|p{.2\linewidth|p{.8\linewidth}}


as above you can not use tabular* like that.

\begin{tabularx}{.8\linewidth}{@{}|X|X|@{}}


As above this would make a table .8\linewidth indented by \parindent.

%\multicolumn{2}{c} The “lipsum” package is a more basic package&


The text should be in the argument to \multicol

%\multicolumn{2}{c}{The “lipsum” package is a more basic package}&


and as you have specified c the cell will not break over a line.

See for example this answer for ways to specify the column widths taking account of cell padding and rule widths

http://tex.stackexchange.com/a/150987/1090

-
Thanks for the link. But I really do not understand any of this advanced tex. I just needed an simple example showing how to use \multicolumn inside a table which is inside multicols environemnt. May be my question was not clear. I'll update it now, with much simpler direct question. –  Nasser Dec 24 '13 at 0:47
@Nasser p{0.7\dimexpr \textwidth-3\arrayrulewidth-4\tabcolsep\relax} doesn't require advance TeX, it is just simple arithemetic. –  David Carlisle Dec 24 '13 at 0:50
But where to put the above? Please do not assume everyone knows Latex as much as you do. I do not even know what to do with the above and where to use it in the code. –  Nasser Dec 24 '13 at 0:56
I put the above in the document, right after the \begin{document}, and I get this error ! You can't use \dimexpr' in horizontal mode. l.15 p{0.7\dimexpr \textwidth-3\arrayrulewidth-4\tabcolsep\relax}` –  Nasser Dec 24 '13 at 1:16
@Nasser did you look at the referenced answer?, it's a tabular p column width, to go in a tabular. The issue here is identical to that question, you want a full width table. –  David Carlisle Dec 24 '13 at 2:44