
我正在嘗試製作一個包含我所有課程作業詳細資訊的表格。我寫了下面的程式碼。它有幾個問題:
- 為什麼編譯時第一頁是空白的(表格在第二頁)?
- 表格似乎在頁面的左邊距留下了很多空間,可以用來放置更寬的第四列,但我似乎無法使用該空間。
- 表格顯示了第二頁底部的頁碼,在第二頁顯示任何內容之後,就不再顯示任何內容。我該怎麼做?
注意:我已將第二列設為 p 列,因為某些講師的真實姓名需要兩行。
這是代碼:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{booktabs}
\begin{document}
\begin{tabular}{p{2.5cm}p{2cm}lp{6cm}}
\toprule[2pt]
Name of Course & Instructor & Book(s) Referred & Brief List of Topics Covered \\
\hline
\\[\defaultaddspace]
Algebra I & ABC & Herstein; M. Artin &
\parbox{6cm}{Basic Set Theory; Group Theory\\(upto Sylow theorems);\\ Introduction to Ring Theory} \\
\\[\defaultaddspace]
Algebra II & DEF & Hoffman and Kunze &
\parbox{6cm}{Linear Algebra \\(upto Spectral theorems)} \\
\\[\defaultaddspace]
Algebra III & GHI & S. Lang &
\parbox{6cm}{Ring and Module Theory\\(covering Hilbert basis theorem and structure theorem for finitely generated abelian groups)}\\
\\[\defaultaddspace]
Algebra IV & JKL & S. Lang &
\parbox{6cm}{Introduction to Field \\ and Galois Theory}\\
\\[\defaultaddspace]
Analysis I & MNO & T. Apostol &
\parbox{6cm}{Real numbers; Sequences and series;\\ Calculus of a single variable \\ (upto Taylor's Theorem)
} \\
\\[\defaultaddspace]
Analysis II & PQR & T. Apostol &
\parbox{6cm}{Riemann integral; Introduction to \\ Calculus of several variables; \\ Metric spaces and elementary \\ topological notions on it} \\
\\[\defaultaddspace]
Analysis III & \parbox{2cm}{STU} & S. Dineen &
\parbox{6cm}{\textbf{Vector Calculus}: multiple integrals, \\ Jacobian formula, line and surface \\ integrals, Green's, Stokes' and Gauss' (Divergence) theorems; \\ Sequences of functions; Weierstrass \\ approximation theorem} \\
\\[\defaultaddspace]
Analysis IV & VWX & Rudin &
\parbox{6cm}{\textbf{Introduction to Function Spaces}:\\ compact metric spaces,\\ C([a,b]) as a complete metric space, \\ Banach's contraction principle, \\ Stone-Weierstrass and Arzela-Ascoli theorems, Fourier series } \\
\\[\defaultaddspace]
Probability Theory I & YZ & Chung; Feller &
\parbox{6cm}{Combinatorial probability and urn models; Conditional probability; \\ Random variables; Expectation; \\ Moment generating functions;\\ Standard distributions(Binomial etc.); \\ Joint and conditional distributions; \\ Weak law of large numbers} \\
\\[\defaultaddspace]
Probability Theory II & YZ & Feller &
\parbox{6cm}{Joint distributions; \\Transformation of variables\\(assuming Jacobian formula);\\ Distributions for sums, maxima/minima, order statistics, etc.; Standard multivariate and sampling distributions; Conditional expectation; Convergence of random variables} \\
\\[\defaultaddspace]
\bottomrule[2pt]
\end{tabular}
\end{document}
答案1
真正的問題是頁面中沒有足夠的空間容納表格。
這就是我的建議:
如果您希望表格拆分為多個頁面,請使用
longtable
同一個套件中的內容。tabular
在這種情況下,表格可以保留在一頁中。您可以使用該
geometry
套件並僅使用以下命令減少表格所在頁面的頁邊距\newgeometry{margin=2cm}
並稍後透過發出恢復正常佈局
\restoregeometry
\defaultaddspace
減少的長度1pt
\setlength{\defaultaddspace}{1pt}
無需使用
\parbox
es 將儲存格內容置中。您可以加載array
包並使用m
而不是p
.您也可以聲明新的列類型M
\newcolumntype{M}[1]{>{\raggedright\arraybackslash}m{#1}}
您也可以用於
\newline
在儲存格內發出換行符。
完整範例:
\documentclass[a4paper,10pt]{article}
\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsthm,array}
\usepackage{booktabs}
\usepackage{array,longtable}
\usepackage{lipsum} %only for the example
\newcolumntype{M}[1]{>{\raggedright\arraybackslash}m{#1}}
\setlength{\defaultaddspace}{1pt}
\begin{document}
\lipsum[1-5]
\newpage
\newgeometry{margin=2cm}
\begin{longtable}{p{2.5cm}p{2cm}lM{6cm}}
\toprule[2pt]
Name of Course & Instructor & Book(s) Referred & Brief List of Topics Covered \\
\hline
\\[\defaultaddspace]
Algebra I & ABC & Herstein; M. Artin &
Basic Set Theory; Group Theory\newline(upto Sylow theorems);\newline Introduction to Ring Theory \\
\\[\defaultaddspace]
Algebra II & DEF & Hoffman and Kunze &
Linear Algebra \newline(upto Spectral theorems) \\
\\[\defaultaddspace]
Algebra III & GHI & S. Lang &
Ring and Module Theory\newline(covering Hilbert basis theorem and structure theorem for finitely generated abelian groups) \\
\\[\defaultaddspace]
Algebra IV & JKL & S. Lang &
Introduction to Field \newline and Galois Theory\\
\\[\defaultaddspace]
Analysis I & MNO & T. Apostol &
Real numbers; Sequences and series;\newline Calculus of a single variable \newline (upto Taylor's Theorem) \\
\\[\defaultaddspace]
Analysis II & PQR & T. Apostol &
Riemann integral; Introduction to \newline Calculus of several variables; \newline Metric spaces and elementary \newline topological notions on it \\
\\[\defaultaddspace]
Analysis III & \parbox{2cm}{STU} & S. Dineen &
\textbf{Vector Calculus}: multiple integrals, \newline Jacobian formula, line and surface \newline integrals, Green's, Stokes' and Gauss' (Divergence) theorems; \newline Sequences of functions; Weierstrass \newline approximation theorem \\
\\[\defaultaddspace]
Analysis IV & VWX & Rudin &
\textbf{Introduction to Function Spaces}:\newline compact metric spaces,\newline C([a,b]) as a complete metric space, \newline Banach's contraction principle, \newline Stone-Weierstrass and Arzela-Ascoli theorems, Fourier series \\
\\[\defaultaddspace]
Probability Theory I & YZ & Chung; Feller &
Combinatorial probability and urn models; Conditional probability; \newline Random variables; Expectation; \newline Moment generating functions;\newline Standard distributions(Binomial etc.); \newline Joint and conditional distributions; \newline Weak law of large numbers \\
\\[\defaultaddspace]
Probability Theory II & YZ & Feller &
Joint distributions; \newline Transformation of variables\newline(assuming Jacobian formula);\newline Distributions for sums, maxima/minima, order statistics, etc.; Standard multivariate and sampling distributions; Conditional expectation; Convergence of random variables \\
\\[\defaultaddspace]
\bottomrule[2pt]
\end{longtable}
\newpage
\restoregeometry
\lipsum[1-5]
\end{document}
輸出:
編輯
p
正如egreg 在他的評論中註意到的那樣,如果您使用普通列而不需要額外的\\
before ,表格看起來可能會更好\\[\defaultaddspace]
。
這是另一種可能性(選擇您最喜歡的一種):
\documentclass[a4paper,10pt]{article}
\usepackage{geometry}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsthm,array}
\usepackage{booktabs}
\usepackage{array,longtable}
\usepackage{lipsum} %only for the example
\begin{document}
\lipsum[1-5]
\newpage
\newgeometry{margin=3cm}
\begin{longtable}{p{2.5cm}p{2cm}lp{6cm}}
\toprule[2pt]
Name of Course & Instructor & Book(s) Referred & Brief List of Topics Covered \\[\defaultaddspace]
\hline
\\
Algebra I & ABC & Herstein; M. Artin &
Basic Set Theory; Group Theory\newline(upto Sylow theorems);\newline Introduction to Ring Theory \\[\defaultaddspace]
Algebra II & DEF & Hoffman and Kunze &
Linear Algebra \newline(upto Spectral theorems) \\[\defaultaddspace]
Algebra III & GHI & S. Lang &
Ring and Module Theory\newline(covering Hilbert basis theorem and structure theorem for finitely generated abelian groups) \\[\defaultaddspace]
Algebra IV & JKL & S. Lang &
Introduction to Field \newline and Galois Theory \\[\defaultaddspace]
Analysis I & MNO & T. Apostol &
Real numbers; Sequences and series;\newline Calculus of a single variable \newline (upto Taylor's Theorem) \\[\defaultaddspace]
Analysis II & PQR & T. Apostol &
Riemann integral; Introduction to \newline Calculus of several variables; \newline Metric spaces and elementary \newline topological notions on it \\[\defaultaddspace]
Analysis III & \parbox{2cm}{STU} & S. Dineen &
\textbf{Vector Calculus}: multiple integrals, \newline Jacobian formula, line and surface \newline integrals, Green's, Stokes' and Gauss' (Divergence) theorems; \newline Sequences of functions; Weierstrass \newline approximation theorem \\[\defaultaddspace]
Analysis IV & VWX & Rudin &
\textbf{Introduction to Function Spaces}:\newline compact metric spaces,\newline C([a,b]) as a complete metric space, \newline Banach's contraction principle, \newline Stone-Weierstrass and Arzela-Ascoli theorems, Fourier series \\[\defaultaddspace]
Probability Theory I & YZ & Chung; Feller &
Combinatorial probability and urn models; Conditional probability; \newline Random variables; Expectation; \newline Moment generating functions;\newline Standard distributions(Binomial etc.); \newline Joint and conditional distributions; \newline Weak law of large numbers \\[\defaultaddspace]
Probability Theory II & YZ & Feller &
Joint distributions; \newline Transformation of variables\newline(assuming Jacobian formula);\newline Distributions for sums, maxima/minima, order statistics, etc.; Standard multivariate and sampling distributions; Conditional expectation; Convergence of random variables \\[\defaultaddspace]
\bottomrule[2pt]
\end{longtable}
\newpage
\restoregeometry
\lipsum[1-5]
\end{document}
答案2
我建議您對錶格執行以下操作,假設它適合一頁:
使用
tabularx
環境而不是tabular
環境,將其寬度設為\textwidth
,並使用X
最後一列的列類型。這會將最後一列的寬度設定為(\textwidth
減去其他三列的寬度)。在最後一欄中使用 raggedright 排版而不是完整的對齊方式;載入該
ragged2e
套件以允許對以 raggedright 模式排版的單字進行連字符。擺脫各種
\parbox
包裝並使用\newline
語句在第 4 列引發換行。將許多
\\ \\[\defaultaddspace]
指令替換為\\[\defaultaddspace]
.如果您確實需要比 提供的更多的垂直空白\defaultaddspace
,只需適當增加該參數的值即可。在下面的範例中,我2.5\defaultaddspace
在代數和分析課程組之後提供了更多的垂直空間。
假設1in
周圍都有邊距,您會得到以下外觀:
\documentclass[a4paper,10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=1in]{geometry}
\usepackage{amsmath,amsthm,booktabs}
\usepackage{tabularx,ragged2e}
\newcolumntype{Y}{>{\RaggedRight\arraybackslash}X}
\begin{document}
\noindent
\begin{tabularx}{\textwidth}{@{} l p{1.75cm} l Y @{}}
\toprule[2pt]
Name of Course & Instructor & Book(s) Referred & Brief List of Topics Covered \\
\midrule
Algebra I & ABC & Herstein; M. Artin &
Basic Set Theory; Group Theory\newline
(upto Sylow theorems);\newline
Introduction to Ring Theory \\[\defaultaddspace]
Algebra II & DEF & Hoffman and Kunze &
Linear Algebra \newline
(upto Spectral theorems) \\[\defaultaddspace]
Algebra III & GHI & S. Lang &
Ring and Module Theory \newline
(covering Hilbert basis theorem and structure theorem for finitely generated
abelian groups)\\[\defaultaddspace]
Algebra IV & JKL & S. Lang &
Introduction to Field and Galois Theory \\[2.5\defaultaddspace]
Analysis I & MNO & T. Apostol &
Real numbers; Sequences and series;\newline
Calculus of a single variable \newline
(upto Taylor's Theorem) \\[\defaultaddspace]
Analysis II & PQR & T. Apostol &
Riemann integral; Introduction to Calculus of several variables; \newline
Metric spaces and elementary topological notions on it \\[\defaultaddspace]
Analysis III & STU & S. Dineen &
\textbf{Vector Calculus}: multiple integrals, Jacobian formula, line and
surface integrals, Green's, Stokes' and Gauss' (Divergence) theorems; \newline
Sequences of functions; \newline
Weierstrass approximation theorem \\[\defaultaddspace]
Analysis IV & VWX & Rudin &
\textbf{Introduction to Function Spaces}:\newline
compact metric spaces, $C([a,b])$ as a complete metric space, Banach's contraction principle,
Stone-Weierstrass and Arzela-Ascoli theorems, Fourier series \\[2.5\defaultaddspace]
Prob.\ Theory I & YZ & Chung; Feller &
Combinatorial probability and urn models; Conditional probability; \newline
Random variables; Expectation; \newline
Moment generating functions;\newline
Standard distributions (Binomial etc.); \newline
Joint and conditional distributions; \newline
Weak law of large numbers \\[\defaultaddspace]
Prob.\ Theory II & YZ & Feller &
Joint distributions; \newline
Transformation of variables (assuming Jacobian formula);\newline
Distributions for sums, maxima\slash minima, order statistics, etc.;\newline
Standard multivariate and sampling distributions;\newline
Conditional expectation; \newline
Convergence of random variables \\
\bottomrule[2pt]
\end{tabularx}
\end{document}
附錄:擴展此設定非常簡單,以便表格可以跨越多個頁面。需要 (i) 加載長桌和可寫的序言中的包(除了tabularx
包之外)和(ii)對錶的頁眉/頁腳結構進行一些更改,使其符合語法longtable
:
首先將目前表的全部內容(從
\begin{tabularx}{\textwidth}{...}
到\end{tabularx}
)放入單獨的文件。將此文件稱為mybiglongtable.tex
. (我相信你能想出一個更合適的名字......)在「驅動檔案」中,插入指令
\LTXtable{\textwidth}{mybiglongtable.tex} % note explicit width indication
就在您希望表格開始的地方。 (A
longtable
不是 LaTeX 意義上的「浮動物件」。)因此,前面的單頁表示例中的驅動程式檔案將如下所示:\documentclass[a4paper,10pt]{article} \usepackage[utf8]{inputenc} \usepackage[margin=1in]{geometry} \usepackage{amsmath,amsthm,booktabs} \usepackage{tabularx,longtable,ltxtable,ragged2e} \newcolumntype{Y}{>{\RaggedRight\arraybackslash}X} \begin{document} \LTXtable{\textwidth}{mybiglongtable.tex} \end{document}
在文件中
mybiglongtable.tex
,進行以下更改:改變
\begin{tabularx}{\textwidth}{@{} l p{1.75cm} l Y @{}}
到
\begin{longtable}{@{} l p{1.75cm} l Y @{}} % no explicit width indication
並將
\end{tabularx}
(在文件末尾)更改為\end{longtable}
.使用
longtable
語法,在 後立即提供所需的頁眉和頁腳信息\begin{longtable}{...}
,如下所示:\toprule[2pt] Name of Course & Instructor & Book(s) Referred & Brief List of Topics Covered \\ \midrule \endfirsthead \multicolumn{4}{@{}l}{\emph{Continued from previous page}}\\ \midrule[\heavyrulewidth] \endhead \midrule[\heavyrulewidth] \multicolumn{4}{r@{}}{\emph{Continued on following page}} \endfoot \bottomrule[2pt] \endlastfoot
請注意,表格頂部和底部的所有規則繪製命令都分配給命令
\endfirsthead
、\endhead
、\endfoot
和之一\endlastfoot
。文件的其餘部分(直到
\end{longtable}
)應包含表格的“主體”,即與課程相關的資訊。您可以像之前的 MWE 中一樣使用\\[\defaultaddspace]
和\\[2.5\defaultaddspace]
來提供一些內容的視覺化分組。