0

Can I use the tabulary package to create a 2-column table, with column1 using 30% of the available width and column2 using 70%? For example:

\begin{tabulary}{|p{30%}|p{70%}|}
...
 \end{tabulary}   
mikey
  • 21

1 Answers1

1

If you know the complete width (which is missing in your code fragment), you can simply calculate the widths:

\documentclass{article}

\usepackage{tabulary}

\begin{document}

\begin{tabulary}{1.0\textwidth}{|p{.3\textwidth}|p{.7\textwidth}|}
a & b\\
\end{tabulary}

\end{document}

As this does not use any of the special features of tabulary, it can be simplified to

\documentclass{article}

\begin{document}

\begin{tabular}{|p{.3\textwidth}|p{.7\textwidth}|}
a & b\\
\end{tabular}

\end{document}

(or even better: make the columns a bit smaller, as currently there is no room for the space around the columns, but the numbers where easier to demonstrate.)

  • You are not using tabulary at all, just use tabular (also the line is overfull by parindent+3\arrayrulewidth+4\tabcolsep=40.2pt) – David Carlisle Jul 23 '18 at 15:00
  • samcarter: Can you explain your solution? Are you defining the total table width as 1.0, then dividing the column widths up to make 1.0? – mikey Jul 23 '18 at 15:02
  • @DavidCarlisle I don't understand either why the OP uses tabulary for two p columns. – samcarter_is_at_topanswers.xyz Jul 23 '18 at 15:11
  • @mikey The point is that you know the total with of the table from the first argument of tabulary in the above example 1\textwidth from the requirements that a) the lenghts have to add up to < the total width and b) your desired ratio is 3:7 you can calculate them. For the easier case of a normal table, you can do the same. – samcarter_is_at_topanswers.xyz Jul 23 '18 at 15:13
  • A legacy document I am working on uses tabulary. If I can get this to work using tabulary, that is the best solution. – mikey Jul 23 '18 at 15:14
  • @mikey no basically you can not get it to work with tabulary, the only purpose of tabulary is to calculate the column widths automatically and you want to pre-specify them so you need to undo everything the package does which is possible, but not using the package is a lot easier. – David Carlisle Jul 23 '18 at 15:18
  • @DavidCarlisle: But the auto-width feature of tabulary doesn't seem to work if I have multiple lines of text in a table cell. There seems to be an hyphenation issue if a table cell contains multiple lines of text. Cell text can run over into the adjacent cell, and column1 is compressed, leading to table header text being uneccesarily hyphenated and/or line wrapped. Hence my search for using defined percentage column widths. And samcarter's solution seems to work well. – mikey Jul 23 '18 at 15:24
  • @mikey Maybe it would be better to ask a question about your real problem and not for your workaround? – samcarter_is_at_topanswers.xyz Jul 23 '18 at 15:26
  • @samcarter: Thanks. I will create a separate question about the cell overflow issue I have seen with tabulary. – mikey Jul 23 '18 at 15:28
  • @mikey no. Using tabulary without an LCR column is (exactly) like using tabularx without an X, there is no way the tabulary code can do anything to make the table the specified width. No error message is given but it is basically user error and can only do anything remotely acceptable if you force the column widths by hand to add up to \textwidth, by which time you may as well use tabular – David Carlisle Jul 23 '18 at 15:40