简单按键事件表

简单按键事件表

请考虑下图所示的简单时间线表(摘自一本书)。

在此处输入图片描述

下面的 MWE 将其定义为环境,

\documentclass[twocolumn,10pt]{article}
\usepackage{mathpazo,calc,tikz}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{microtype}
\usepackage{array,booktabs,colortbl}
\color[gray]{.1}
\makeatletter
\newif\if@top
\@toptrue
\if@top \def\one{\leavevmode\par}\def\two{\vfill}\fi
\newif\if@center
\if@center\def\one{\vfill}\def\two{\vfill}\fi
\newif\if@bottom
\@bottomtrue
\if@bottom\def\one{\vfill}\def\two{}\fi


\makeatother
\newenvironment{timeline}[1][1534--40]{%
    \one
    \long\def\Row##1##2{\rowcolor{yellow!8}[5pt][2pt]\textbf{##1}&##2 \\ \midrule}%
    \setlength{\tabcolsep}{0pt}%
    \arrayrulecolor{yellow}%
    \renewcommand{\arraystretch}{1}%
    \sffamily
    \noindent
    \newlength\templength
    \settowidth{\templength}{#1}%
    \addtolength{\templength}{1em}%
        \begin{tabular}{p{\templength}p{\dimexpr\columnwidth-\templength-2pt}}%
             \hline
             \multicolumn{2}{>{\columncolor{yellow!25}[5pt][3pt]}l}{\bfseries KEY EVENTS}\\
             \hline}%
       {\end{tabular}%
       \two\vspace{-6.5pt}
}
\begin{document}
\lipsum[1-5]

\begin{timeline}
  \Row{1520}{Death of Raphael. His later works were considered the beginning of Mannerism}
  \Row{1528}{Sack of Rome. Spreads Mannerism across Italy and France}
  \Row{c.\thinspace1528}{Jacobo Pontomo finishes his \textit{Deposition}, a Florentine altarpiece in the Mannerist style}
  \Row{1534--40}{Girolano Parmigiano paints \textit{The\newline Madonna of the Long Neck}}
  \Row{1541}{Birth of El Grego}
\end{timeline}

\end{document}

你能帮忙让它更接近原版吗?两个常见问题,关键事件标题,作为行周围的框架混合,第二个删除底部的额外空间以使其与左列文本的基线对齐(在 MWE 中手动更正)。还有其他细微的差异。

在此处输入图片描述

最好从书中的背景来看待这种风格艺术作者为罗伯特·卡明 (Robert Cumming),DK Publications 出版。

在此处输入图片描述

答案1

我尝试复制表格,但除了 Arial Narrow 之外,我没有其他更窄的字体。我没有构建完整的环境,但我认为直接在表格中输入内容可能会更好。所以我使用了pgfplotstabledatatool也可以很好地完成。因此,这是一种概念性答案。

我把表放在 tikz 节点中,并将标题设为外部节点(真是令人惊讶)

编辑现在它可以作为一个简单的命令\timeline{<Title>}{<tabular content>}

\documentclass[twocolumn]{article}
\usepackage{fontspec}
\setsansfont[Ligatures=TeX]{Arial Narrow}
% ================================================================================
\usepackage{pgfplotstable,booktabs,colortbl,microtype,xparse,kantlipsum}
\usetikzlibrary{matrix}
\pgfplotsset{compat=1.8}
% ================================================================================

 \NewDocumentCommand{\timeline}{m+m}{%
 \begin{tikzpicture}[baseline,font=\sffamily]
 \matrix[matrix of nodes,draw=yellow!40,ultra thick,inner sep=0pt,ampersand replacement=\&,nodes={anchor=center},row sep=-.5\pgflinewidth]{
 |[font=\sffamily\bfseries,align=left,fill=yellow!25,text width={7cm},inner ysep=1.2ex]| \hspace{0.75em}#1\\ % Title node
 |[inner xsep=0.5em,inner ysep=1.8ex,fill=yellow!8]|
    {\pgfplotstabletypeset[ % Table inside the second row node
    string type,
    every odd row/.style={after row={\midrule}},
    every even row/.style={after row={\midrule}},
    every last row/.style={after row={}},
    every head row/.style={output empty row},
    display columns/0/.style={column type={@{}p{9mm}},postproc cell content/.style={@cell content=\textbf{####1}}},
    display columns/1/.style={column type={p{5.3cm}@{}}},
    col sep=ampersand, row sep=\\, header=false,
    ]{#2}}\\   % End of node, \\ is needed
 };            % End of matrix node
 \end{tikzpicture}
 } 

\begin{document}\sffamily
\kant[1-2]

\timeline{KEY EVENTS}{
      1520             & Death of Raphael. His later works were\newline considered the beginning of Mannerism\\
      1527             & Sack of Rome. Spreads Mannerism\newline across Italy and France\\
      c.\thinspace1528 & Jacobo Pontomo finishes his \emph{Deposition}, a\newline Florentine altarpiece in the Mannerist style\\
      1534--40         & Girolano Parmigiano paints \emph{The\newline Madonna of the Long Neck}\\
      1541             & Birth of El Grego\\
}

\kant[3]

\timeline{BREAKING NEWS}{
      16:55             & Nero is looking hot today\\
      23:00             & Fire!! \\
      05:55             & Smoke on the Water....\newline Fire in the sky!\\
}    
\end{document}

在此处输入图片描述

答案2

它并不漂亮,但可能正是您想要的。黄色很难看清,但如果您将 MWE 设置为蓝色,困难就会变得更加明显。与您的方法的主要区别在于:

1)我使用了两个表格,一个用于标题,一个用于其余部分(这使我避免了multicolumn颜色问题)。

2)我将所有内容都包裹起来,\colorbox以避免行之间出现空白。

在此过程中,我必须用垂直修剪一个盒子\addvbuffer并扔进去一个\strut

\documentclass[twocolumn,10pt]{article}
\usepackage{mathpazo,calc,tikz}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{microtype}
\usepackage{array,booktabs,colortbl}
\usepackage{verbatimbox}
\color[gray]{.1}
\makeatletter
\newif\if@top
\@toptrue
\if@top \def\one{\leavevmode\par}\def\two{\vfill}\fi
\newif\if@center
\if@center\def\one{\vfill}\def\two{\vfill}\fi
\newif\if@bottom
\@bottomtrue
\if@bottom\def\one{\vfill}\def\two{}\fi

\makeatother
\newenvironment{timeline}[1][1534--40]{%
    \one%
    \long\def\Row##1##2{%\rowcolor{blue!8}[5pt][2pt]
      \textbf{##1}&##2 \\ \midrule}%
    \setlength{\tabcolsep}{0pt}%
    \arrayrulecolor{yellow!75}%
    \renewcommand{\arraystretch}{1}%
    \sffamily%
    \noindent%
    \newlength\templength%
    \settowidth{\templength}{#1}%
    \kern-2.5pt\addvbuffer[-3pt 1pt]{\colorbox{yellow!25}%
    {\begin{tabular}{@{\hspace{-.5pt}}p{\columnwidth}}%
      \bfseries KEY EVENTS%
    \end{tabular}}}\\%
    \addtolength{\templength}{1em}%
        \begin{tabular}{p{\templength}%
          p{\dimexpr\columnwidth-\templength%
           %-2pt%
           }}%
%             \hline%
%             \multicolumn{2}{>{\columncolor{yellow!25}%
%               [3pt][3pt]%
%               }l}{\bfseries KEY EVENTS}\\%
%             \hline%
       }%
       {\end{tabular}%
       \two\vspace{-6.5pt}%
}
\begin{document}
\lipsum[1-5]

\newsavebox{\mytab}
\sbox{\mytab}{\colorbox{yellow!8}{\vbox{%
\begin{timeline}
  \Row{1520}{Death of Raphael. His later works were considered the beginning of Mannerism}
  \Row{1528}{Sack of Rome. Spreads Mannerism across Italy and France}
  \Row{c.\thinspace1528}{Jacobo Pontomo finishes his \textit{Deposition}, a Florentine altarpiece in the Mannerist style}
  \Row{1534--40}{Girolano Parmigiano paints \textit{The\newline Madonna of the Long Neck}}
  \Row{1541}{Birth of El Grego}
\end{timeline}%
}}}
\vfill
\color{yellow!75}\fboxsep=-.25pt\relax\fbox{\usebox{\mytab}\strut}
\end{document}

在此处输入图片描述

答案3

虽然我的其他解决方案试图建立在您的 MWE 方法之上,但这个解决方案是从头开始开发的。tabular我没有使用解决方案,而是在这里使用了一个stackengine解决方案,即我开始在当前堆栈下方堆叠颜色\parboxes,从标题行开始。直到环境关闭后,堆栈才会输出。我相信编码比方法干净得多tabular

\Row宏现在采用一个可选参数,如果设置为x,则会阻止设置底线,该底线应用于最终条目。

我也用蓝色做了这个解决方案,因为我注意到在某些显示器上它比黄色更容易看到。显然,您需要将值重置blueyellow以获得图形的方案。

为了更好地匹配您的字体,我添加的最后一个调整是将表格垂直拉伸 15%。如果您不喜欢它或者找到其他字体来替代,可以很容易地删除它。

\documentclass[twocolumn,10pt]{article}
\usepackage{mathpazo,calc,tikz}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{microtype}
\usepackage{array,booktabs,colortbl}
\usepackage{scalerel}
\usepackage[usestackEOL]{stackengine}[2013-09-11]
\color[gray]{.1}
\makeatletter
\newif\if@top
\@toptrue
\if@top \def\one{\leavevmode\par}\def\two{\vfill}\fi
\newif\if@center
\if@center\def\one{\vfill}\def\two{\vfill}\fi
\newif\if@bottom
\@bottomtrue
\if@bottom\def\one{\vfill}\def\two{}\fi

\makeatother

\newcommand\Row{}
\newlength\templength%
\def\stackalignment{l}%
\newenvironment{timeline}[1][1534--40]{%
  \one%
  \sffamily%
  \settowidth{\templength}{#1~~~}%
  \renewcommand\Row[3][l]{%
    \savestack{\anchorbox}{%
      \stackunder[0pt]{\anchorbox}{\colorbox{blue!8}{%
        \parbox{\columnwidth}{%
          \makebox[\templength][l]{\textbf{##2}}%
          \parbox[t]{\columnwidth-\templength}{\strut##3\strut}}}%
      }%
    }%
    \if x##1\else%
      \savestack{\anchorbox}{%
        \stackunder[-3pt]{\anchorbox}{\colorbox{blue!8}{%
          \color{black!75}\rule{\columnwidth}{.4pt}}%
        }%
      }%
    \fi%
  }%
  \savestack{\anchorbox}{\colorbox{blue!25}%
  {\parbox{\columnwidth}{\strut\bfseries KEY EVENTS}}}%
}%
{%
  \fboxsep=0pt\relax%
  \fboxrule=.4pt%
  \noindent\kern-3pt\color{blue!75}\fbox{\vstretch{1.15}{\anchorbox}}%
  \two%
}
\begin{document}
\lipsum[1-5]

\begin{timeline}
  \Row{1520}{Death of Raphael. His later works were considered the beginning of Mannerism}
  \Row{1528}{Sack of Rome. Spreads Mannerism across Italy and France}
  \Row{c.\thinspace1528}{Jacobo Pontomo finishes his \textit{Deposition}, a Florentine altarpiece in the Mannerist style}
  \Row{1534--40}{Girolano Parmigiano paints \textit{The\newline Madonna of the Long Neck}}
  \Row[x]{1541}{Birth of El Greco}
\end{timeline}%
\end{document}

在此处输入图片描述

相关内容