Problemas estranhos de alinhamento na tabela da lista de cursos

Problemas estranhos de alinhamento na tabela da lista de cursos

Estou tentando fazer uma tabela contendo detalhes de todos os meus cursos. Eu escrevi o seguinte código. Existem alguns problemas com isso:

  1. Por que aparece uma primeira página em branco na compilação (com a tabela na segunda página)?
  2. A tabela parece deixar muito espaço na margem esquerda da página, o que poderia ser usado para ter uma quarta coluna mais larga, mas não consigo usar esse espaço.
  3. A tabela ultrapassa o número da página na parte inferior da segunda página e nada é exibido depois do que é exibido na página 2. Tenho vários outros cursos e gostaria que esta tabela ocupasse aproximadamente 3 páginas. Como eu posso fazer isso?

Observação: criei a segunda coluna como uma coluna p, pois os nomes reais de alguns instrutores exigem duas linhas.

Aqui está o código:

\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}

Responder1

O verdadeiro problema é que não há espaço suficiente para a tabela na página.

Isto é o que eu sugiro:

  1. Use longtabledo mesmo pacote em vez de tabularse desejar que a tabela seja dividida em páginas.

  2. Neste caso a tabela pode ficar em uma página. Você pode usar o geometrypacote e reduzir as margens da página apenas para a página onde está a tabela com o comando

    \newgeometry{margin=2cm}
    

    e restaure o layout normal posteriormente emitindo

    \restoregeometry
    
  3. Reduza o comprimento \defaultaddspacepara1pt

    \setlength{\defaultaddspace}{1pt}
    
  4. Não há necessidade de usar \parboxes para centralizar o conteúdo das células. Você pode carregar o arraypacote e usá-lo mem vez de p. Você também pode declarar um novo tipo de colunaM

    \newcolumntype{M}[1]{>{\raggedright\arraybackslash}m{#1}}
    

    Você também pode usar \newlinepara emitir quebras de linha dentro das células.

Exemplo completo:

\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} 

Saída:

insira a descrição da imagem aqui


EDITAR

Como egreg observa em seu comentário, provavelmente a tabela ficará melhor se você usar uma pcoluna normal sem a necessidade de \\before \\[\defaultaddspace].

Esta é outra possibilidade (escolha a que mais lhe agrada):

\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} 

insira a descrição da imagem aqui

Responder2

Eu sugiro que você faça o seguinte com a tabela, supondo que ela caiba em uma página:

  • Use um tabularxambiente em vez de um tabularambiente, defina sua largura como \textwidthe use o Xtipo de coluna para a coluna final. Isto definirá a largura da coluna final como ( \textwidthmenos as larguras das outras três colunas).

  • Use composição tipográfica irregular em vez de justificativa completa na coluna final; carregue o ragged2epacote para permitir a hifenização de palavras compostas no modo raggedright.

  • Livre-se dos vários \parboxwrappers e use \newlineinstruções para induzir quebras de linha na coluna 4. (Obrigado, @egreg!)

  • Substitua as muitas \\ \\[\defaultaddspace]instruções por \\[\defaultaddspace]. Se você realmente precisar de mais espaços em branco verticais do que os fornecidos por \defaultaddspace, simplesmente aumente o valor desse parâmetro de forma adequada. No exemplo abaixo, utilizo 2.5\defaultaddspacepara fornecer mais espaço vertical após os grupos dos cursos de álgebra e análise.

Supondo margens ao 1inredor, você teria a seguinte aparência:

insira a descrição da imagem aqui

\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}

Termo aditivo: é simples estender essa configuração para que a tabela possa abranger diversas páginas. É necessário (i) carregar oMesa compridaeltxtávelpacotes (além do tabularxpacote) no preâmbulo e (ii) fazer algumas alterações na estrutura de cabeçalho/rodapé da tabela para que ela esteja em conformidade com a longtablesintaxe:

  • Comece colocando todo o conteúdo da tabela atual (de \begin{tabularx}{\textwidth}{...}até \end{tabularx}) em umarquivo separado. Chame esse arquivo, digamos, mybiglongtable.tex. (Tenho certeza que você pode encontrar um nome mais adequado...)

  • No "arquivo do driver", insira a instrução

    \LTXtable{\textwidth}{mybiglongtable.tex} % note explicit width indication
    

    exatamente onde você deseja que a mesa comece. (A longtablenão é um "objeto flutuante" no sentido LaTeX da palavra.) O arquivo de driver do exemplo anterior de tabela de página única ficaria assim:

    \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}
    
  • No arquivo mybiglongtable.tex, faça as seguintes alterações:

    • Mudar

      \begin{tabularx}{\textwidth}{@{} l p{1.75cm} l Y @{}}
      

      para

      \begin{longtable}{@{} l p{1.75cm} l Y @{}} % no explicit width indication
      

      e mude \end{tabularx}(no final do arquivo) para \end{longtable}.

    • Usando longtablea sintaxe, forneça as informações necessárias de cabeçalho e rodapé imediatamente após \begin{longtable}{...}, digamos o seguinte:

      \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
      

      Observe que todos os comandos de desenho de regras para as partes superiores e inferiores da tabela são atribuídos a um dos comandos \endfirsthead, \endhead, \endfoote \endlastfoot.

    • O restante do arquivo (até \end{longtable}) deverá conter o “corpo” da tabela, ou seja, as informações referentes aos cursos. Você pode usar \\[\defaultaddspace]e \\[2.5\defaultaddspace]como no MWE anterior para fornecer algum agrupamento visual do conteúdo.

informação relacionada