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 know that you can combine tabularx and longtable functionality with either ltxtable or ltablex, but is there something similar for tabulary? My searching has come up dry when looking for any way to get tabulary to work with very long tables.

The table I am working with has large amounts of text that requires line breaking in multiple columns. Some cells have very little, and some have a lot, and I would like to see the column widths juggled to minimize total table length. I realize I could manually do this with the {>{\hsize=.5\hsize}X>{\hsize=1.5\hsize}X} functionality in tabularx, but what I'm making is intended to be a template that should work well with any particular arrangement of data that gets thrown in. Am I doomed to using tabularx and manually adjusting the hsize numbers each time I want to make a table?

share|improve this question
1  
TX isn't that bad: "doomed" probably isn't the word I'd use:-) If you don't need table headers repeated at the page breaks you could just inbox the TY table. If you do need headings probably isn't impossibly difficult to modify ltxtable so that it mixes TY and longtable instead of TX, but I'm busy this week so someone else might like the challenge:-) –  David Carlisle Oct 17 '12 at 23:10
    
Yeah, the repeated table headers are unfortunately pretty key. I manually defined a few p columns in TX that pretty well handle things, but there is still an l column I can imagine getting a little strange in fringe cases that I'm not sure I can bear to hard code a width for. –  Eric Oct 18 '12 at 15:20
add comment

1 Answer

Updated to support setting longtable \LTleft and \LTright margins.

enter image description here

\documentclass{article}
\usepackage{longtable,tabulary}
\setlength\textheight{10\baselineskip}
\topmargin-4\baselineskip
\headheight0pt
\pdfpageheight18\baselineskip

\def\a{Red green blue yellow green. }
\def\b{One two three four five six. }
\makeatletter

\def\ltabulary{%
\def\endfirsthead{\\}%
\def\endhead{\\}%
\def\endfoot{\\}%
\def\endlastfoot{\\}%
\def\tabulary{%
  \def\TY@final{%
\def\endfirsthead{\LT@end@hd@ft\LT@firsthead}%
\def\endhead{\LT@end@hd@ft\LT@head}%
\def\endfoot{\LT@end@hd@ft\LT@foot}%
\def\endlastfoot{\LT@end@hd@ft\LT@lastfoot}%
\longtable}%
  \let\endTY@final\endlongtable
  \TY@tabular}%
\dimen@\columnwidth
\advance\dimen@-\LTleft
\advance\dimen@-\LTright
\tabulary\dimen@}

\def\endltabulary{\endtabulary}

\makeatother

\begin{document}


\begin{ltabulary}{LLL}
HEAD 1& HEAD 2& HEAD 3\endhead
\a\a&\a&\a\a\a\\
\b\b&\b&\b\b\b\\
x&y&z\\
x&y&z\\
x&y&z\\
x&y&z\\
\b\b&\a&\b\a\b\\
x&y&z\\
x&y&z\\
x&y&z\\
x&y&z\\
x&y&z\\
\end{ltabulary}


\noindent X\dotfill X

\LTleft=2cm

\begin{ltabulary}{LLL}
HEAD 1& HEAD 2& HEAD 3\endhead
\a\a&\a&\a\a\a\\
\b\b&\b&\b\b\b\\
x&y&z\\
x&y&z\\
x&y&z\\
x&y&z\\
\b\b&\a&\b\a\b\\
x&y&z\\
x&y&z\\
x&y&z\\
\end{ltabulary}

\noindent X\dotfill X
\end{document}
share|improve this answer
    
Thanks for this solution. The only problem with it is that it removes all the hyphenations. Is it possible to have them back? It is especially true for the cases when there is a long word in a narrow column. –  v_2e Aug 21 '13 at 13:07
1  
@v_2e tabulary L column is same as \begin{flushleft} which prefers leaving a line short over hyphenation, you can use J columns instead for justified columns with hyphenation (the usual latex default). words longer than the column width would hyphenate with either L or J but the first word of a paragraph doesn't hyphenate in TeX start the text with \hspace*{0pt} to get round that (true in general not just in this sort of table) –  David Carlisle Aug 21 '13 at 13:10
add comment

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.