I am trying to write a report for my project in LaTex.
I am able to put code onto my LaTex Document, but I wanted to know if it is possible to import my output cell which is a table onto my LaTex document?
If not, any other suggestions where I should not create my own table for every output.
[Tex/LaTex] Copy Output table in Jupyter for LaTex Document
tablesterminal-output
Related Solutions
None of the following is to contradict tohecz's comment above, especially regarding serif versus sans-serif fonts. But if you can't find a better table design, or can't do a landscape table, then you'll have to do more than just set a font size for the table. You'll probably have to:
- Set a smaller font size for the table
- Set a smaller column separation inside the tabular environment
- Use smaller margins than the LaTeX default
You'll also want to read the documentation on the booktabs
package for some advice on table layout, particularly on avoiding excess rules (and probably all vertical ones). And the siunitx
package is good for aligning columns of measurements.
One result using booktabs
and siunitx
, with dummy body text for size comparison:
Annotated code, broken up for legibility and inline comments (but compiles fine in this form):
\documentclass[a4paper]{article}
\usepackage[margin=3cm]{geometry} % reduce margins to 3cm on all sides
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage{lipsum}
\setlength{\tabcolsep}{2pt} % reduce column separation from default of 6pt
\begin{document}
\lipsum[1]
\begin{table}
\caption{Some caption}
\centering
\scriptsize
% default tabular column formatting:
% left-aligned label (date),
% 5 measured values with 2 figures before decimal and 1 after,
% 5 measured values with 3 figures before decimal and none after,
% centered label (power),
% 5 measured values with 2 figures before decimal and 1 after,
% 5 measured values with 3 figures before decimal and none after,
\begin{tabular}{
l
*{5}{S[table-format=2.1]}
*{5}{S[table-format=3.0]}
c
*{5}{S[table-format=2.1]}
*{5}{S[table-format=3.0]}}
% Place a top-of-table rule across all columns
\toprule
% Leave a blank column, span centered label over 10 columns,
% leave a blank column, span another centered label over 10 columns
& \multicolumn{10}{c}{Male} & & \multicolumn{10}{c}{Female} \\
% Place a mid-table rule over columns 2-11 and 13-22
\cmidrule{2-11} \cmidrule{13-22}
% Leave a blank column, span centered label over 5 columns,
% span centered label over 5 columns, span centered label over 5 columns,
% span centered label over 5 columns
& \multicolumn{5}{c}{Weight} & \multicolumn{5}{c}{Height} &
& \multicolumn{5}{c}{Weight} & \multicolumn{5}{c}{Height} \\
% Place mid-table rules over columns 2-6, 7-11, 13-17, and 18-22
% (trimmed on both left and right ends)
\cmidrule(lr){2-6} \cmidrule(lr){7-11} \cmidrule(lr){13-17} \cmidrule(lr){18-22}
% Enclose all repeated headers in braces to keep siunitx from trying to interpret them
Birthday & {Min} & {Q1} & {Med} & {Q3} & {Max} & {Min} & {Q1} & {Med} & {Q3} & {Max} &
Power & {Min} & {Q1} & {Med} & {Q3} & {Max} & {Min} & {Q1} & {Med} & {Q3} & {Max} \\
% Place a mid-table rule across all columns
\midrule
Jan 2012
& 50.0 & 60.0 & 70.0 & 80.0 & 90.0 & 140 & 150 & 160 & 170 & 180 &
100 & 50.0 & 60.0 & 70.0 & 80.0 & 90.0 & 140 & 150 & 160 & 170 & 180 \\
& 50.0 & 60.0 & 70.0 & 80.0 & 90.0 & 140 & 150 & 160 & 170 & 180 &
120 & 50.0 & 60.0 & 70.0 & 80.0 & 90.0 & 140 & 150 & 160 & 170 & 180 \\
& 50.0 & 60.0 & 70.0 & 80.0 & 90.0 & 140 & 150 & 160 & 170 & 180 &
340 & 50.0 & 60.0 & 70.0 & 80.0 & 90.0 & 140 & 150 & 160 & 170 & 180 \\
% Place a mid-table rule across all columns
\midrule
Feb 2012
& 50.0 & 60.0 & 70.0 & 80.0 & 90.0 & 140 & 150 & 160 & 170 & 180 &
100 & 50.0 & 60.0 & 70.0 & 80.0 & 90.0 & 140 & 150 & 160 & 170 & 180 \\
& 50.0 & 60.0 & 70.0 & 80.0 & 90.0 & 140 & 150 & 160 & 170 & 180 &
120 & 50.0 & 60.0 & 70.0 & 80.0 & 90.0 & 140 & 150 & 160 & 170 & 180 \\
& 50.0 & 60.0 & 70.0 & 80.0 & 90.0 & 140 & 150 & 160 & 170 & 180 &
340 & 50.0 & 60.0 & 70.0 & 80.0 & 90.0 & 140 & 150 & 160 & 170 & 180 \\
% Place a bottom-of-table rule across all columns
\bottomrule
\end{tabular}
\end{table}
\end{document}
The resulting table is legible, but just barely fits in the margins provided. If you had more data or bigger margins, this table would rapidly approach what some people refer to as an "eye chart" table. At that point, you'd definitely have to change the requirements or move away from one giant table entirely. Maybe go to one table for males, one for females. Maybe just put a figure in with confidence interval bars or similar.
There is no hope of fitting a table with such long headers. A way out can be using symbols for them, that are explained at the bottom of the table:
\documentclass{article}
\usepackage{array,siunitx,booktabs}
\begin{document}
\begin{table}
\centering
\addtolength{\tabcolsep}{-3pt}
\begin{tabular}{
@{}
>{\itshape}l
S[table-format=3.2]
S[table-format=-3.2]
S[table-format=-2.2]
S[table-format=-2.2]
S[table-format=-2.2]
S[table-format=-1.2]
S[table-format=-5.2]
@{}
}
\toprule
& {(1)} &{(2)} &{(3)} &{(4)} & {(5)} &{(6)} & {(7)} \\
\midrule
\textit{Values} & 57,00 & 57,00 & 57,00 & 57,00 & 57,00 & 57,00 & 57,00 \\
\textit{Missing Values} & 0,00 & 0,00 & 0,00 & 0,00 & 0,00 & 0,00 & 0,00 \\
\textit{Min} & -9,23 & -27,11 & -5,38 & -3,36 & -12,10 & -1,00 & -1882,35 \\
\textit{Max} & 11,26 & 17,55 & 1,28 & 2,40 & 11,30 & 0,40 & 1386,67 \\
\textit{Range} & 20,49 & 44,66 & 6,66 & 5,76 & 23,40 & 1,40 & 3269,02 \\
\textit{Sum} & 0,77 & -2,53 & -88,41 & -37,13 & -45,90 & 2,40 & -12800,35 \\
\textit{Median} & -0,22 & 0,24 & -1,40 & -0,43 & -0,40 & 0,05 & 0,00 \\
\textit{Mean} & 0,01 & -0,04 & -1,55 & -0,65 & -0,81 & 0,04 & -224,57 \\
\textit{SE of Mean} & 0,57 & 1,05 & 0,21 & 0,11 & 0,48 & 0,04 & 69,92 \\
\textit{95\% CI of Mean} & 1,13 & 2,09 & 0,42 & 0,23 & 0,96 & 0,07 & 140,08 \\
\textit{Variance} & 18,25 & 62,31 & 2,49 & 0,74 & 13,06 & 0,08 & 278697,92 \\
\textit{Std.\ Dev.} & 4,27 & 7,89 & 1,58 & 0,86 & 3,61 & 0,28 & 527,92 \\
\textit{Coef.\ Var.} & 317,97 & -177,59 & -1,02 & -1,32 & -4,49 & 6,64 & -2,35 \\
\midrule[\heavyrulewidth]
%%% Headers
\multicolumn{8}{l}{(1) \textbf{oenb\_dependent}} \\
\multicolumn{8}{l}{(2) \textbf{carReg}} \\
\multicolumn{8}{l}{(3) \textbf{cpi}} \\
\multicolumn{8}{l}{(4) \textbf{primConstTot}} \\
\multicolumn{8}{l}{(5) \textbf{resProp.Dwell}} \\
\multicolumn{8}{l}{(6) \textbf{cbre.office.primeYield}} \\
\multicolumn{8}{l}{(7) \textbf{cbre.retail.capitalValue}} \\
\bottomrule
\end{tabular}
\caption{Output of pre-selected and finally chosen variables of the variable selection process.}
\label{table:initialDataSet}
\end{table}
\end{document}
I also recommend siunitx
and booktabs
, that give more professional appearance to the table. The value after table-format
is the number of digits in the integer and decimal part, with an optional sign if present in the column. In column one I don't specify the sign, because it's taken care of by the last entry; similarly for the sixth column, the two digit first entry is taken care of by the minus sign.
Since the table was still overfull by about 41pt, I removed 3pt of separation between columns (two spaces are inserted between columns, and 6 times 7 makes 42).
Best Answer
Since you are using pandas you can use
dataset.to_latex(dataset.tex)
This would give you a latex table. Also you can just get the whole jupyter notebook as LaTeX code and than take what ever you want from it. For this you could usejupyter nbconvert /path/jupyterscript.ipynb --to latex
This would give you your table and the code you needed to generate the table.