我的问题与 sgmoye 对来自 Indesign 的启发性练习表。我想通过让练习编号与“练习”一词垂直对齐来扩展这个答案。从下图中可以看出,红线上方有一个小的垂直空间,这意味着目前情况并非如此。基本上,我想保留白色框周围的灰色边框,但让“练习”与这个白色框中的数字对齐。
此外,我想为每个练习添加不同的标题,该标题也应与练习编号垂直对齐。它应该位于给定图像右侧的白色间隙中(tikz 矩形外)。有人可以告诉我如何做到这一点吗?我已经添加了我正在使用的代码。
% !TEX encoding = UTF-8 Unicode
% !TEX TS-program = XeLaTeX
\documentclass[11pt,a4paper,landscape]{article}
\usepackage{tikz}
\usepackage{multicol}
\usepackage{lipsum}
\usepackage{tikzpagenodes}
\usepackage{eso-pic}
\usepackage{enumitem}
\usepackage{amsmath}
\usepackage{microtype}
\usepackage[margin=1in]{geometry}
\usetikzlibrary{calc}
\usetikzlibrary{shapes.multipart}
\newcounter{exrc}
\newcommand{\exstep}{%
\stepcounter{exrc}%
\tikz[baseline]\node[anchor=base,%
rectangle split,
rectangle split parts=2,
draw=gray,
thick,
rectangle split horizontal,
outer sep = 0pt,
rectangle split part fill={gray,white},
inner sep=0pt] (exx) at (0,0)
{\textcolor{white}{\bfseries\extype}\nodepart{two}\textcolor{black}{\bfseries\theexrc}};
}
\AddToShipoutPictureBG{%
\begin{tikzpicture}[remember picture,overlay]
\draw[thick,rounded corners]
($(current page text area.south west)+(-12pt,-12pt)$)
rectangle
($(current page text area.north east)+(12pt,12pt)$);
\node[white,fill=gray,rounded corners]
at ($(current page text area.north)+(0,12pt)$)
%% Change `Exercises' to suit
{\bfseries\sffamily\hspace*{1em}Exercises\hspace*{1em}};
\end{tikzpicture}
}
%% There are two environments, `exci` for exercises using `enumerate`,
%% and `exct` for text exercises that do not use `enumerate`.
%% Both have an optional argument to change the name of the
%% exercise on the fly. See the included examples.
\newenvironment{exci}[2][Exercise]{%
\def\extype{#1}%
\leavevmode\exstep\par
\smallskip
#2
\begin{enumerate}[leftmargin=*,noitemsep,nosep]
}{%
\end{enumerate}
\bigskip
\def\extype{Exercise}%
}
\newenvironment{exct}[1][Exercise]{%
\def\extype{#1}%
\leavevmode\exstep\par
\smallskip
}{%
\bigskip
\def\extype{Exercise}%
}
\setlength{\columnseprule}{0.4pt}
\parindent0pt
\begin{document}
\begin{multicols*}{2}
\begin{exci}{Calculate the following limits:}
\item $$\lim\displaylimits_{x \to2}\frac{4x^3-5x-22}{x^{2}-x-2}$$
\end{exci}
\end{multicols*}
\end{document}
答案1
您需要添加rectangle split part align=base
到节点选项。但随后您可能想要增加inner sep
。我inner sep=1pt
在下面的代码中使用了。
\newcommand{\exstep}{%
\stepcounter{exrc}%
\tikz[baseline]\node[anchor=base,%
rectangle split,
rectangle split parts=2,
rectangle split part align=base,
draw=gray,
thick,
rectangle split horizontal,
outer sep = 0pt,
rectangle split part fill={gray,white},
inner sep=1pt] (exx) at (0,0)
{\textcolor{white}{\bfseries\extype}\nodepart{two}\textcolor{black}{\bfseries\theexrc}};
}