
我想在序言中說,我使用 LaTeX 的經驗非常有限。我已閱讀文檔,但對我來說很難理解。
我的表如下:
這裡的東西很少。正如您所看到的,當涉及到值時,我的列間距非常小,它們與列標題不對齊。我想我需要使用“\multiplerows{}
也許”來解決這個問題。這是正確的道路嗎?我將如何實現這個`
此外,每個新條目之間的間距還可以,但也較大。是否有一個我可以實現的單行程式碼,可以將間距比我猜測的預設設定稍微縮小一點?
這是我的程式碼(改編自線上範本):
\begin{document}
\begin{slide*}
\begin{table}
\centering
\footnotesize
\caption{Breakdown by Voivodeship}
\label{tab:kathoden}
\begin{tabular}{@{}nd{1.1}*{4}{d{1.2}}d{1.1}d{3.2}@{}}
\toprule
\multicolumn{1}{N}{\bf{Voivodeship}} &
\multicolumn{1}{N}{Total Cases} &
\multicolumn{1}{N}{Cases 100k} &
\multicolumn{1}{N}{Total Deaths} &
\multicolumn{1}{N}{Deaths 100k} &
\multicolumn{1}{N}{Total Tests} &
\multicolumn{1}{N}{Total Tests} &
\multicolumn{1}{N}{Case Fatality} \\
\cmidrule(r){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}%
\cmidrule(lr){5-5}\cmidrule(lr){6-6}\cmidrule(lr){7-7}\cmidrule(lr){8-8}
Lower Silesia & 1100 & 1.15 & 1.25 & 1.45 & 1 & 220 & 20 \\
Kuyavian-Pomeranian & 1.5 & 1.8 & 1.9 & 2.2 & 1.5 & 20 & 20 \\
Lublin & 2 & 2.3 & 2.5 & 2.9 & 2 & 20 & 20 \\
Lubusz & 3 & 2.9 & 3.1 & 3.6 & 2.5 & 20 & 20 \\
Lodz & 3.5 & 3.5 & 10.8 & 4.3 & 20 & 20 & 20 \\
Lesser Poland & 3.5 & 3.5 & 3.8 & 4.3 & 20 & 20 & 29\\
Mazowieckie & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264.$---$ \\
Opole & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264.$---$ \\
Subcarpathian & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264.$---$ \\
Podlasie & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264.$---$ \\
Pomorskie & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264.$---$ \\
Silesian & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264.$---$ \\
Pomorskie & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264.$---$ \\
Pomorskie & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264.$---$ \\
Pomorskie & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264.$---$ \\
Silesian & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264.$---$ \\
\bottomrule
\end{tabular}
\end{table}
\end{slide*}
\end{document}
答案1
由於您是乳膠桌子世界的新手,我將給您我的食譜。
首先,LaTeX 用於製作漂亮的列印材料或幻燈片。對於實際處理數字的工作,我使用 Excel。 (其他人會使用 R 或其他一些統計軟體包。)
在電子表格中,您可以根據您的品味或您要複製的原始內容或您必須遵守的風格進行計算、對列重新排序、在標題或單元格中添加顏色、設置線條等,直到獲得最終結果最終報告或論文。
然後你就可以使用 LaTeX。您可以逐個儲存格、逐行手動輸入表格,或從來源匯出它(強烈建議)。
我使用 Excel 外掛程式 excel2latex 產生(幾乎)最終程式碼。最重要的是,它將忠實地導出內容,因此翻譯中不會丟失任何內容。
https://ctan.org/pkg/excel2latex?lang=en
複製到剪貼簿並將其貼上到您的 LateX 程式碼中。它將編譯沒有錯誤。 (在這種情況下,您需要添加包booktabs
)。
然後,您可以使用太多專用於表格的 LaTex 包,使表格適合頁面、更改樣式等。
對於此範例,我添加了較短的列規則和標題(從原始內容剪下並貼上)。其他修飾留給讀者。 :)
\documentclass[landscape]{article}
\usepackage{booktabs} %required
\usepackage{multirow} %not needed here but useful
\usepackage{geometry} % to fit the table in the page
\begin{document}
% Table generated by Excel2LaTeX from sheet 'Sheet1'
\begin{table}[htbp]
\centering
\caption{Breakdown by Voivodeship}
\begin{tabular}{lccccccc}
\toprule
\textbf{Voivodeship} & Total Cases & Cases 100k & Total Deaths & Deaths 100k & Total Tests & Total Tests & Case Fatality \\
\cmidrule(r){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}%
\cmidrule(lr){5-5}\cmidrule(lr){6-6}\cmidrule(lr){7-7}\cmidrule(lr){8-8}
% \midrule
Lower Silesia & 1100 & 1.15 & 1.25 & 1.45 & 1 & 220 & 20 \\
Kuyavian-Pomeranian & 1.5 & 1.8 & 1.9 & 2.2 & 1.5 & 20 & 20 \\
Lublin & 2 & 2.3 & 2.5 & 2.9 & 2 & 20 & 20 \\
Lubusz & 3 & 2.9 & 3.1 & 3.6 & 2.5 & 20 & 20 \\
Lodz & 3.5 & 3.5 & 10.8 & 4.3 & 20 & 20 & 20 \\
Lesser Poland & 3.5 & 3.5 & 3.8 & 4.3 & 20 & 20 & 29 \\
Mazowieckie & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & --- \\
Opole & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & --- \\
Subcarpathian & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & --- \\
Podlasie & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & --- \\
Pomorskie & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & --- \\
Silesian & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & --- \\
Pomorskie & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & --- \\
Pomorskie & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & --- \\
Pomorskie & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & --- \\
Silesian & 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & --- \\
\bottomrule
\end{tabular}%
\label{tab:addlabel}%
\end{table}%
\end{document}
答案2
我會直接用 LaTeX 來寫你的表格。
使用包S
中定義的列類型siunitx
,左計算為\tabcolsep
宏\extracolsep{\fill}}
,對於列標題,使用包\thead
中定義的命令makecell
。此表格可以適合投影片,因為使用了字體大小\scriptsize
:
\documentclass{beamer}
\usepackage{array, booktabs, makecell}
\renewcommand\theadfont{\scriptsize\bfseries}
\renewcommand\theadgape{}
\usepackage{siunitx}
\begin{document}
\begin{frame}
\frametitle{My beautiful table}
\begin{table}
\centering
\scriptsize
\setlength\tabcolsep{0pt}
\caption{Breakdown by Voivodeship}
\label{tab:kathoden}
\begin{tabular*}{\linewidth}{@{\extracolsep{\fill}} l
S[table-format=4.1]
S[table-format=1.2]
S[table-format=2.2]
S[table-format=1.2]
S[table-format=2.1]
S[table-format=3.0]
S[table-format=2.0]
}
\toprule
\thead{Voivodeship}
& {\thead{Total\\ Cases}}
& {\thead{\\Cases\\ 100k}}
& {\thead{Total\\ Deaths}}
& {\thead{Deaths \\100k}}
& {\thead{Total\\ Tests}}
& {\thead{Total\\ Tests}}
& {\thead{Case\\ Fatality}} \\
\midrule
% \cmidrule(r){1-1}\cmidrule(lr){2-2}\cmidrule(lr){3-3}\cmidrule(lr){4-4}%
% \cmidrule(lr){5-5}\cmidrule(lr){6-6}\cmidrule(lr){7-7}\cmidrule(lr){8-8}
Lower Silesia
& 1100 & 1.15 & 1.25 & 1.45 & 1 & 220 & 20 \\
Kuyavian-Pomeranian
& 1.5 & 1.8 & 1.9 & 2.2 & 1.5 & 20 & 20 \\
Lublin
& 2 & 2.3 & 2.5 & 2.9 & 2 & 20 & 20 \\
Lubusz
& 3 & 2.9 & 3.1 & 3.6 & 2.5 & 20 & 20 \\
Lodz
& 3.5 & 3.5 & 10.8 & 4.3 & 20 & 20 & 20 \\
Lesser Poland
& 3.5 & 3.5 & 3.8 & 4.3 & 20 & 20 & 29 \\
Mazowieckie
& 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & {---} \\
Opole
& 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & {---} \\
Subcarpathian
& 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & {---} \\
Podlasie
& 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & {---} \\
Pomorskie
& 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & {---} \\
Silesian
& 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & {---} \\
Pomorskie
& 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & {---} \\
Pomorskie
& 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & {---} \\
Pomorskie
& 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & {---} \\
Silesian
& 3.5 & 3.5 & 3.8 & 4.3 & 3 & 264 & {---} \\
\bottomrule
\end{tabular*}
\end{table}
\end{frame}
\end{document}