Scale LaTeX tables so they don't exceed columnwidth.
This commit is contained in:
parent
0e2605ffdf
commit
e8ddcfd997
2 changed files with 37 additions and 33 deletions
|
@ -470,9 +470,13 @@ tableRowToLaTeX header aligns widths cols = do
|
||||||
AlignRight -> "\\raggedleft"
|
AlignRight -> "\\raggedleft"
|
||||||
AlignCenter -> "\\centering"
|
AlignCenter -> "\\centering"
|
||||||
AlignDefault -> "\\raggedright"
|
AlignDefault -> "\\raggedright"
|
||||||
|
-- scale factor compensates for extra space between columns
|
||||||
|
-- so the whole table isn't larger than columnwidth
|
||||||
|
let scaleFactor = 0.97 ** fromIntegral (length aligns)
|
||||||
let toCell 0 _ c = c
|
let toCell 0 _ c = c
|
||||||
toCell w a c = "\\begin{minipage}" <> valign <>
|
toCell w a c = "\\begin{minipage}" <> valign <>
|
||||||
braces (text (printf "%.2f\\columnwidth" w)) <>
|
braces (text (printf "%.2f\\columnwidth"
|
||||||
|
(w * scaleFactor))) <>
|
||||||
(halign a <> cr <> c <> cr) <> "\\end{minipage}"
|
(halign a <> cr <> c <> cr) <> "\\end{minipage}"
|
||||||
let cells = zipWith3 toCell widths aligns renderedCells
|
let cells = zipWith3 toCell widths aligns renderedCells
|
||||||
return $ hsep (intersperse "&" cells) $$ "\\\\\\noalign{\\medskip}"
|
return $ hsep (intersperse "&" cells) $$ "\\\\\\noalign{\\medskip}"
|
||||||
|
|
|
@ -54,34 +54,34 @@ Multiline table with caption:
|
||||||
|
|
||||||
\begin{longtable}[c]{@{}clrl@{}}
|
\begin{longtable}[c]{@{}clrl@{}}
|
||||||
\hline\noalign{\medskip}
|
\hline\noalign{\medskip}
|
||||||
\begin{minipage}[b]{0.15\columnwidth}\centering
|
\begin{minipage}[b]{0.13\columnwidth}\centering
|
||||||
Centered Header
|
Centered Header
|
||||||
\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright
|
||||||
Left Aligned
|
Left Aligned
|
||||||
\end{minipage} & \begin{minipage}[b]{0.16\columnwidth}\raggedleft
|
\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft
|
||||||
Right Aligned
|
Right Aligned
|
||||||
\end{minipage} & \begin{minipage}[b]{0.34\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright
|
||||||
Default aligned
|
Default aligned
|
||||||
\end{minipage}
|
\end{minipage}
|
||||||
\\\noalign{\medskip}
|
\\\noalign{\medskip}
|
||||||
\hline\noalign{\medskip}
|
\hline\noalign{\medskip}
|
||||||
\begin{minipage}[t]{0.15\columnwidth}\centering
|
\begin{minipage}[t]{0.13\columnwidth}\centering
|
||||||
First
|
First
|
||||||
\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
|
||||||
row
|
row
|
||||||
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedleft
|
\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
|
||||||
12.0
|
12.0
|
||||||
\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
|
||||||
Example of a row that spans multiple lines.
|
Example of a row that spans multiple lines.
|
||||||
\end{minipage}
|
\end{minipage}
|
||||||
\\\noalign{\medskip}
|
\\\noalign{\medskip}
|
||||||
\begin{minipage}[t]{0.15\columnwidth}\centering
|
\begin{minipage}[t]{0.13\columnwidth}\centering
|
||||||
Second
|
Second
|
||||||
\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
|
||||||
row
|
row
|
||||||
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedleft
|
\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
|
||||||
5.0
|
5.0
|
||||||
\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
|
||||||
Here's another one. Note the blank line between rows.
|
Here's another one. Note the blank line between rows.
|
||||||
\end{minipage}
|
\end{minipage}
|
||||||
\\\noalign{\medskip}
|
\\\noalign{\medskip}
|
||||||
|
@ -94,34 +94,34 @@ Multiline table without caption:
|
||||||
|
|
||||||
\begin{longtable}[c]{@{}clrl@{}}
|
\begin{longtable}[c]{@{}clrl@{}}
|
||||||
\hline\noalign{\medskip}
|
\hline\noalign{\medskip}
|
||||||
\begin{minipage}[b]{0.15\columnwidth}\centering
|
\begin{minipage}[b]{0.13\columnwidth}\centering
|
||||||
Centered Header
|
Centered Header
|
||||||
\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[b]{0.12\columnwidth}\raggedright
|
||||||
Left Aligned
|
Left Aligned
|
||||||
\end{minipage} & \begin{minipage}[b]{0.16\columnwidth}\raggedleft
|
\end{minipage} & \begin{minipage}[b]{0.14\columnwidth}\raggedleft
|
||||||
Right Aligned
|
Right Aligned
|
||||||
\end{minipage} & \begin{minipage}[b]{0.34\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[b]{0.30\columnwidth}\raggedright
|
||||||
Default aligned
|
Default aligned
|
||||||
\end{minipage}
|
\end{minipage}
|
||||||
\\\noalign{\medskip}
|
\\\noalign{\medskip}
|
||||||
\hline\noalign{\medskip}
|
\hline\noalign{\medskip}
|
||||||
\begin{minipage}[t]{0.15\columnwidth}\centering
|
\begin{minipage}[t]{0.13\columnwidth}\centering
|
||||||
First
|
First
|
||||||
\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
|
||||||
row
|
row
|
||||||
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedleft
|
\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
|
||||||
12.0
|
12.0
|
||||||
\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
|
||||||
Example of a row that spans multiple lines.
|
Example of a row that spans multiple lines.
|
||||||
\end{minipage}
|
\end{minipage}
|
||||||
\\\noalign{\medskip}
|
\\\noalign{\medskip}
|
||||||
\begin{minipage}[t]{0.15\columnwidth}\centering
|
\begin{minipage}[t]{0.13\columnwidth}\centering
|
||||||
Second
|
Second
|
||||||
\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
|
||||||
row
|
row
|
||||||
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedleft
|
\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
|
||||||
5.0
|
5.0
|
||||||
\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
|
||||||
Here's another one. Note the blank line between rows.
|
Here's another one. Note the blank line between rows.
|
||||||
\end{minipage}
|
\end{minipage}
|
||||||
\\\noalign{\medskip}
|
\\\noalign{\medskip}
|
||||||
|
@ -145,23 +145,23 @@ Multiline table without column headers:
|
||||||
|
|
||||||
\begin{longtable}[c]{@{}clrl@{}}
|
\begin{longtable}[c]{@{}clrl@{}}
|
||||||
\hline\noalign{\medskip}
|
\hline\noalign{\medskip}
|
||||||
\begin{minipage}[t]{0.15\columnwidth}\centering
|
\begin{minipage}[t]{0.13\columnwidth}\centering
|
||||||
First
|
First
|
||||||
\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
|
||||||
row
|
row
|
||||||
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedleft
|
\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
|
||||||
12.0
|
12.0
|
||||||
\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
|
||||||
Example of a row that spans multiple lines.
|
Example of a row that spans multiple lines.
|
||||||
\end{minipage}
|
\end{minipage}
|
||||||
\\\noalign{\medskip}
|
\\\noalign{\medskip}
|
||||||
\begin{minipage}[t]{0.15\columnwidth}\centering
|
\begin{minipage}[t]{0.13\columnwidth}\centering
|
||||||
Second
|
Second
|
||||||
\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[t]{0.12\columnwidth}\raggedright
|
||||||
row
|
row
|
||||||
\end{minipage} & \begin{minipage}[t]{0.16\columnwidth}\raggedleft
|
\end{minipage} & \begin{minipage}[t]{0.14\columnwidth}\raggedleft
|
||||||
5.0
|
5.0
|
||||||
\end{minipage} & \begin{minipage}[t]{0.34\columnwidth}\raggedright
|
\end{minipage} & \begin{minipage}[t]{0.30\columnwidth}\raggedright
|
||||||
Here's another one. Note the blank line between rows.
|
Here's another one. Note the blank line between rows.
|
||||||
\end{minipage}
|
\end{minipage}
|
||||||
\\\noalign{\medskip}
|
\\\noalign{\medskip}
|
||||||
|
|
Loading…
Add table
Reference in a new issue