
Ich versuche, eine Tabelle mit Details zu all meinen Kursarbeiten zu erstellen. Ich habe den folgenden Code geschrieben. Es gibt ein paar Probleme damit:
- Warum wird beim Kompilieren eine leere erste Seite ausgegeben (mit der Tabelle auf der zweiten Seite)?
- Die Tabelle scheint am linken Seitenrand viel Platz zu lassen, der für eine breitere vierte Spalte genutzt werden könnte, aber ich scheine diesen Platz nicht nutzen zu können.
- Die Tabelle geht über die Seitenzahl am unteren Ende der zweiten Seite hinaus, und nach dem, was auf Seite 2 angezeigt wird, wird nichts mehr angezeigt. Ich habe mehrere andere Kurse und möchte, dass sich diese Tabelle über ungefähr 3 Seiten erstreckt. Wie kann ich das machen?
Hinweis: Die zweite Spalte habe ich als P-Spalte angelegt, da die Realnamen mancher Dozenten zweizeilig sind.
Hier ist der Code:
\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}
Antwort1
Das eigentliche Problem besteht darin, dass auf der Seite nicht genügend Platz für die Tabelle vorhanden ist.
Ich schlage Folgendes vor:
Verwenden Sie
longtable
stattdessen dasselbe Paket,tabular
wenn Sie die Tabelle auf mehrere Seiten aufteilen möchten.In diesem Fall kann die Tabelle auf einer Seite bleiben. Sie können das
geometry
Paket verwenden und die Seitenränder nur für die Seite verkleinern, auf der sich die Tabelle befindet, mit dem Befehl\newgeometry{margin=2cm}
und stellen Sie das normale Layout später wieder her, indem Sie
\restoregeometry
Reduzieren Sie die Länge
\defaultaddspace
auf1pt
\setlength{\defaultaddspace}{1pt}
Es ist nicht nötig, es zu verwenden
\parbox
, um den Inhalt von Zellen zu zentrieren. Sie können dasarray
Paket laden undm
anstelle von verwendenp
. Sie können auch einen neuen Spaltentyp deklarierenM
\newcolumntype{M}[1]{>{\raggedright\arraybackslash}m{#1}}
Sie können damit auch
\newline
Zeilenumbrüche innerhalb von Zellen vornehmen.
Vollständiges Beispiel:
\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}
Ausgabe:
BEARBEITEN
Wie egreg in seinem Kommentar bemerkt, sieht die Tabelle wahrscheinlich besser aus, wenn Sie eine normale Spalte verwenden, ohne dass ein zusätzliches „vorher“ p
erforderlich ist .\\
\\[\defaultaddspace]
Dies ist eine weitere Möglichkeit (wählen Sie die aus, die Ihnen am besten gefällt):
\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}
Antwort2
Ich würde vorschlagen, dass Sie mit der Tabelle Folgendes machen, vorausgesetzt, sie passt auf eine Seite:
Verwenden Sie eine
tabularx
Umgebung anstelle einertabular
Umgebung, legen Sie deren Breite auf fest\textwidth
und verwenden Sie denX
Spaltentyp für die letzte Spalte. Dadurch wird die Breite der letzten Spalte auf (\textwidth
abzüglich der Breiten der anderen drei Spalten) festgelegt.Verwenden Sie in der letzten Spalte den Raggedright-Satz anstelle der vollständigen Blocksatzfunktion. Laden Sie das
ragged2e
Paket, um die Silbentrennung von im Raggedright-Modus gesetzten Wörtern zu ermöglichen.Entfernen Sie die verschiedenen
\parbox
Wrapper und verwenden Sie\newline
Anweisungen, um Zeilenumbrüche in Spalte 4 einzufügen. (Danke, @egreg!)Ersetzen Sie die vielen
\\ \\[\defaultaddspace]
Anweisungen durch\\[\defaultaddspace]
. Wenn Sie wirklich mehr vertikalen Leerraum benötigen als durch bereitgestellt wird\defaultaddspace
, erhöhen Sie einfach den Wert dieses Parameters entsprechend. Im folgenden Beispiel verwende ich ,2.5\defaultaddspace
um mehr vertikalen Platz nach den Gruppen der Algebra- und Analysekurse bereitzustellen.
Wenn Sie Ränder rundherum annehmen 1in
, erhalten Sie das folgende Erscheinungsbild:
\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}
Nachtrag: Es ist ganz einfach, dieses Setup zu erweitern, so dass die Tabelle mehrere Seiten umfassen kann. Man muss (i) dielanger TischUndltxtabellePakete (zusätzlich zum tabularx
Paket) in der Präambel und (ii) einige Änderungen an der Kopf-/Fußzeilenstruktur der Tabelle vornehmen, sodass sie der longtable
Syntax entspricht:
Beginnen Sie damit, den gesamten Inhalt der aktuellen Tabelle (von
\begin{tabularx}{\textwidth}{...}
bis\end{tabularx}
) in einseparate Datei. Nennen Sie diese Datei beispielsweisemybiglongtable.tex
. (Ich bin sicher, Ihnen fällt ein passenderer Name ein ...)Fügen Sie in der „Treiberdatei“ die Anweisung ein
\LTXtable{\textwidth}{mybiglongtable.tex} % note explicit width indication
genau dort, wo die Tabelle beginnen soll. (A
longtable
ist kein „schwebendes Objekt“ im Sinne von LaTeX.) Die Treiberdatei aus dem früheren Beispiel mit der einseitigen Tabelle würde daher folgendermaßen aussehen:\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}
Nehmen Sie in der Datei
mybiglongtable.tex
die folgenden Änderungen vor:Ändern
\begin{tabularx}{\textwidth}{@{} l p{1.75cm} l Y @{}}
Zu
\begin{longtable}{@{} l p{1.75cm} l Y @{}} % no explicit width indication
und ändern Sie
\end{tabularx}
(am Ende der Datei) in\end{longtable}
.longtable
Geben Sie die erforderlichen Kopf- und Fußzeileninformationen unmittelbar danach mithilfe der Syntax ein\begin{longtable}{...}
, etwa wie folgt:\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
Beachten Sie, dass alle Befehle zum Zeichnen von Regeln für die Ober- und Unterseite der Tabelle einem der Befehle
\endfirsthead
,\endhead
,\endfoot
, und zugewiesen sind\endlastfoot
.Der Rest der Datei (bis
\end{longtable}
) sollte den „Hauptteil“ der Tabelle enthalten, also die Informationen zu den Kursen. Sie können\\[\defaultaddspace]
und\\[2.5\defaultaddspace]
wie im früheren MWE verwenden, um eine visuelle Gruppierung der Inhalte bereitzustellen.