Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a series of tables that are going to be very (very!) wide, but with only 3 rows. Is there any way I can get the tables to wrap within my margins, without having to break the rows within the .tex file itself?

share|improve this question
    
Welcome to TeX.sx No need to addd thanks, simply upvote good answers to your Q that you receive. –  Peter Jansson Feb 7 '13 at 20:14
    
Please provide a bit more information about the tables' structure. E.g., how many columns do they contain, and what is the content of each cell: Simple integers, decimal numbers, text, images, or a mixture of all of the above? –  Mico Feb 7 '13 at 20:15
1  
Outside-of-the-box answer: You could flip the orientation of the table and make it a three-column table that wraps vertically .In order to make better use of the horizontal space then, you could use a multicols environment from the multicol package. Let me know if that’s an option, I can add a sample. –  doncherry Feb 7 '13 at 20:24

2 Answers 2

enter image description here

\documentclass{article}
\usepackage{array}

\newbox\zz
\makeatletter
\newenvironment{wraptable}
{\def\endarray{\crcr \egroup
\global\setbox1\lastbox
\unskip\global\setbox3\lastbox
\unskip\global\setbox5\lastbox
 \egroup \@arrayright \gdef\@preamble{}}%
\setbox0\hbox\bgroup\tabular}
{\endtabular\egroup
\setbox0\hbox{}
\loop
\ifdim\wd1=0pt
{\raggedright\unhbox0\par}%
\else
\global\setbox1\hbox{\unhbox1 \unskip\global\setbox7\lastbox}%
\global\setbox3\hbox{\unhbox3 \unskip\global\setbox9\lastbox}%
\global\setbox5\hbox{\unhbox5 \unskip\global\setbox\zz\lastbox}%
\setbox0\hbox{\vbox{\box\zz\box9\box7\kern10pt}\penalty0\unhbox0}%
\repeat
}
\makeatother

\begin{document}

\begin{wraptable}{*{26}{l}}
a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z\\
1&2&3&1&2&3&1&2&3&1&2&3&1&2&3&1&2&3&1&2&3&1&2&3&1&2\\
one&two&three&one&two&three&one&two&three&one&two&three&
one&two&three&one&two&three&one&two&three&one&two&three&
one&two
\end{wraptable}


\end{document}
share|improve this answer

Not easily. But there are ways around this, to avoid duplicating your table structure (and promote consistency). The example below uses the idea from Easiest way to delete a column? to selectively hide certain columns in a table:

enter image description here

\documentclass{article}
\usepackage{array,tabularx}% http://ctan.org/pkg/{array,tabularx}
\newcolumntype{H}{>{\setbox0=\hbox\bgroup}c<{\egroup}@{}}
\newcommand{\mywidetable}{%
  one & two & three & four & five & six & seven & eight & nine & ten \\
  1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 10
}
\newcommand{\insertmywidetable}[1]{%
  \begin{tabular}{#1}\mywidetable\end{tabular}}
\newcommand{\insertmywidetablex}[1]{%
  \begin{tabularx}{\linewidth}{#1}\mywidetable\end{tabularx}}
\setlength{\parindent}{0pt}% Just for this example
\begin{document}

\insertmywidetable{*{10}{c}}

\hrulefill

\insertmywidetable{ccc*{7}{H}}\par
\insertmywidetable{HHHcccHHHH}\par
\insertmywidetable{*{6}{H}cccc}

\hrulefill

\insertmywidetablex{XXX*{7}{H}}\par
\insertmywidetablex{HHHXXXHHHH}\par
\insertmywidetablex{*{6}{H}XXXX}

\end{document}

You would store the contents of the table in a macro (say \mywidetable) and then create a table-setting macro \insertmywidetable. The latter takes an argument for the column specification, where you selectively use H to hide that particular column, or something else (X if using tabularx, say, or c, or...).

Two examples are shown, first using a traditional tabular with c-columns, then using a tabularx with X-columns.

share|improve this answer
    
Starting an answer with "No" That's just setting a challenge:-) –  David Carlisle Feb 7 '13 at 21:16
    
@DavidCarlisle: Well well, and you rose to the occasion. I'll keep my inferior attempt at showing authority with an edit... :-| –  Werner Feb 7 '13 at 21:18
    
actually I forgot to +1 yours (done now) It's probably more robust if you want to use tabularx or fancy inter-column rules or something. –  David Carlisle Feb 7 '13 at 21:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.