使用表格设计书籍条目单元格

使用表格设计书籍条目单元格

我试图将大量的书籍条目(#、标题、作者)挤进一页进行打印。我不确定我是否嵌套\tabular正确,但以下是我想到的内容:

\documentclass[10pt,a4paper]{article}
\usepackage[margin=0.2in]{geometry}

\usepackage{array}
\usepackage{color}
\usepackage[usenames,dvipsnames]{xcolor}

% define command for book entry
\newcommand{\bookentry}[3]{
  \begin{tabular}{cp{1.25in}}
    \textcolor{gray}{\textbf{#1}} &
           {\tiny \textsc{#2}} \newline
           {\tiny \textbf{#3}} 
  \end{tabular}
}

\begin{document}

\begin{tabular}{cc}

  \begin{tabular}{|l|l|} 
    \hline
    \bookentry{1}{Siddhartha}{Herman Hesse} & 
    \bookentry{2}{Old Man And The Sea}{Ernest Hemingway} \\ \hline
    \bookentry{3}{Catch 22}{Joseph Heller} & 
    \bookentry{4}{The Elements of Style}{Strunk \& White} \\ \hline
  \end{tabular} &

  \begin{tabular}{|l|l|}
    \hline
    \bookentry{1}{The Latex Companion}{Mittelbach \& Goossens} & 
    \bookentry{2}{The Elements of Typographic Style}{Robert Bringhurst} \\ \hline
    \bookentry{3}{Feynman Lectures On Computation}{Richard P. Feynman \& Anthony Hey} &
    \bookentry{4}{The TeXbook}{Donald Knuth} \\ \hline
  \end{tabular}

\end{tabular}

\end{document}

输出如下:

书籍条目

  1. 我如何更改标题和作者之间的行距?我认为它使用 10pt 间距,但我将其用于\tiny文本。
  2. 我如何格式化数字以使它们填满单元格的高度并垂直和水平居中?

答案1

其中一种方法是使用\parbox代替bookentry

\newcommand{\bookentry}[3]{%
    \textbf{#1}~\parbox{1.35in}{\tiny\textsc{#2} \\ \textbf{#3}}%
}

得出的结果是:

在此处输入图片描述

您应该考虑的另一个变化是使用自动编号:

\newcounter{BookCount}
\newcommand{\bookentry}[2]{%
    \stepcounter{BookCount}%
    \textbf{\arabic{BookCount}}~\parbox{1.35in}{\tiny\textsc{#1} \\ \textbf{#2}}%
}

代码:手动编号

\documentclass[10pt,a4paper]{article}
\usepackage[margin=0.2in]{geometry}

\usepackage{array}
\usepackage{color}
\usepackage[usenames,dvipsnames]{xcolor}

% define command for book entry
\newcommand{\bookentry}[3]{%
           \textbf{#1}~\parbox{1.35in}{\tiny\textsc{#2} \\ \textbf{#3}}%
}


\begin{document}

\begin{tabular}{cc}

  \begin{tabular}{|l|l|} 
    \hline
    \bookentry{1}{Siddhartha}{Herman Hesse} & 
    \bookentry{2}{Old Man And The Sea}{Ernest Hemingway} \\ \hline
    \bookentry{3}{Catch 22}{Joseph Heller} & 
    \bookentry{4}{The Elements of Style}{Strunk \& White} \\ \hline
  \end{tabular} &

  \begin{tabular}{|l|l|}
    \hline
    \bookentry{1}{The Latex Companion}{Mittelbach \& Goossens} & 
    \bookentry{2}{The Elements of Typographic Style}{Robert Bringhurst} \\ \hline
    \bookentry{3}{Feynman Lectures On Computation}{Richard P. Feynman \& Anthony Hey} &
    \bookentry{4}{The TeXbook}{Donald Knuth} \\ \hline
  \end{tabular}

\end{tabular}

\end{document}

代码:自动编号

\documentclass[10pt,a4paper]{article}
\usepackage[margin=0.2in]{geometry}

\usepackage{array}
\usepackage{color}
\usepackage[usenames,dvipsnames]{xcolor}

% define command for book entry
\newcounter{BookCount}
\newcommand{\bookentry}[2]{%
    \stepcounter{BookCount}%
    \textbf{\arabic{BookCount}}~\parbox{1.35in}{\tiny\textsc{#1} \\ \textbf{#2}}%
}


\begin{document}

\begin{tabular}{cc}
  \begin{tabular}{|l|l|} 
    \hline
    \bookentry{Siddhartha}{Herman Hesse} & 
    \bookentry{Old Man And The Sea}{Ernest Hemingway} \\ \hline
    \bookentry{Catch 22}{Joseph Heller} & 
    \bookentry{The Elements of Style}{Strunk \& White} \\ \hline
  \end{tabular} &

  \setcounter{BookCount}{0}%
  \begin{tabular}{|l|l|}
    \hline
    \bookentry{The Latex Companion}{Mittelbach \& Goossens} & 
    \bookentry{The Elements of Typographic Style}{Robert Bringhurst} \\ \hline
    \bookentry{Feynman Lectures On Computation}{Richard P. Feynman \& Anthony Hey} &
    \bookentry{The TeXbook}{Donald Knuth} \\ \hline
  \end{tabular}
\end{tabular}

\end{document}

相关内容