我发现这个模板在 TeX.SE 上(感谢 u/Qrrbrbirlbel),但想知道是否有人可以帮助我添加在绿色解决方案框中输入的功能。
\documentclass{article}
\pagestyle{empty}
\usepackage[top=.5in, left=.5in, right=.5in, bottom=.5in]{geometry}
\usepackage{tikz}
\usepackage{calc}
\usetikzlibrary{arrows, positioning, calc}
\tikzset{
all nodes/.style={
rounded corners=6pt,
},
small node/.style={
all nodes,
inner sep=5pt,
anchor=north west,
},
big node/.style={
all nodes,
align=center,
},
question/.style={
big node,
draw=red,
fill=red!10,
text width=.55\textwidth,
inner sep=20pt,
},
question label/.style={
small node,
draw=red,
fill=red!30,
},
hint/.style={
big node,
draw=blue,
fill=blue!10,
text width=.35\textwidth,
inner sep=5pt,
},
hint label/.style={
small node,
draw=blue,
fill=blue!30,
},
answer/.style={
big node,
draw=green,
fill=green!10,
},
answer label/.style={
small node,
draw=green,
fill=green!30,
},
reset/.style={
rounded corners=0pt,
minimum height=0pt,
inner sep=.3333em,
text width=,% reset
}
}
\newlength{\nodeheighta}
\newlength{\nodeheightb}
\newcommand\WS[2]{%
\sbox0{\tikz[inner sep=0pt,outer sep=0pt]{\node[question] (Question) {#1};}}%
\sbox1{\tikz[inner sep=0pt,outer sep=0pt]{\node[hint] (Hint) {#2};}}%
\setlength{\nodeheighta}{\ht0}%
\setlength{\nodeheightb}{\ht1}%
\ifdim\nodeheighta<\nodeheightb\nodeheighta=\nodeheightb\fi%
\noindent%
\begin{tikzpicture}
\node[question, minimum height=\nodeheighta,] (Question) {#1};
\node[question label] at (Question.north west) {Question};
\node[hint, minimum height=\nodeheighta, right=0pt of Question.north east, anchor=north west] (Hint) {#2};
\node[hint label] at (Hint.north west) {Hint};
\path let
\p2 = ($(Question.west)-(Hint.east)$),
\n2 = {veclen(\p2)-\pgflinewidth}, % 0.4pt is the width of the border line
\p3 = ($(Question.north)-(Question.south)$),
\n3 = {\textheight-veclen(\p3)-10.4pt}
in node[
answer,
text height=\n3,
below=0pt of Question.south west,
anchor=north west,
minimum width=\n2
] (Answer) {};
% The Label
\node[answer label, anchor=north west, inner sep=5pt] at (Answer.north west) {Answer};
\end{tikzpicture}%
}
注意:这是一个 headmat 文件。用法是
\WS{Question}{Hint}
我想得到
\WS{Question}{Hint}{Solution}.
另外,我希望能够在顶部添加标题(页眉)/页码。
非常感谢!
答案1
下面给出了两种不同的选项。我在代码中用注释指出了我添加或更改的内容。仅在第一个选项中(至少目前),我添加了一个页眉,其中包含页码和由第四个参数指定的标题\WS
,即\WS{Question}{Hint}{\lipsum[1]}{Title}
\documentclass{article}
\pagestyle{empty}
\usepackage{lipsum}
\usepackage[top=.75in, left=.5in, right=.5in, bottom=.5in]{geometry} % increased top margin a bit
\usepackage{tikz}
\usetikzlibrary{arrows, positioning, calc}
\usepackage{fancyhdr}
\fancypagestyle{foo}{
\fancyhf{}
\fancyhead[R]{\thepage}
\fancyhead[L]{\rightmark}
\renewcommand\headrulewidth{0pt}
}
\pagestyle{foo}
\tikzset{
all nodes/.style={
rounded corners=6pt,
},
small node/.style={
all nodes,
inner sep=5pt,
anchor=north west,
},
big node/.style={
all nodes,
align=center,
},
question/.style={
big node,
draw=red,
fill=red!10,
text width=.55\textwidth,
inner sep=20pt,
},
question label/.style={
small node,
draw=red,
fill=red!30,
},
hint/.style={
big node,
draw=blue,
fill=blue!10,
text width=.35\textwidth,
inner sep=5pt,
},
hint label/.style={
small node,
draw=blue,
fill=blue!30,
},
answer/.style={
big node,
draw=green,
fill=green!10,
},
answer label/.style={
small node,
draw=green,
fill=green!30,
},
reset/.style={
rounded corners=0pt,
minimum height=0pt,
inner sep=.3333em,
text width=,% reset
}
}
\newlength{\nodeheighta}
\newlength{\nodeheightb}
\newcommand\WS[4]{% <-- changed 2 to 4
\sbox0{\tikz[inner sep=0pt,outer sep=0pt]{\node[question] (Question) {#1};}}%
\sbox1{\tikz[inner sep=0pt,outer sep=0pt]{\node[hint] (Hint) {#2};}}%
\setlength{\nodeheighta}{\ht0}%
\setlength{\nodeheightb}{\ht1}%
\ifdim\nodeheighta<\nodeheightb\nodeheighta=\nodeheightb\fi%
\markright{#4}% <-- added
\noindent%
\begin{tikzpicture}
\node[question, minimum height=\nodeheighta,] (Question) {#1};
\node[question label] at (Question.north west) {Question};
\node[hint, minimum height=\nodeheighta, right=0pt of Question.north east, anchor=north west] (Hint) {#2};
\node[hint label] at (Hint.north west) {Hint};
\path let
\p2 = ($(Question.west)-(Hint.east)$),
\n2 = {veclen(\p2)-\pgflinewidth}, % 0.4pt is the width of the border line
\p3 = ($(Question.north)-(Question.south)$),
\n3 = {\textheight-veclen(\p3)-10.4pt}
in node[
answer,
minimum height=\n3, % <-- changed to minimum height
below=0pt of Question.south west,
anchor=north west,
minimum width=\n2
] (Answer) {}; % <-- added #3
% The Label
\node[answer label, anchor=north west, inner sep=5pt] (AnswerLabel) at (Answer.north west) {Answer}; % added (Answerlabel)
% added the following line
\node[text width=0.95\textwidth, below right] at ([shift={(3mm,-3mm)}]AnswerLabel.south west) {#3};
\end{tikzpicture}%
}
\begin{document}
\WS{Question}{Hint}{\lipsum[1]}{Title}
\WS{Question2}{Hint2}{\lipsum[2]}{Title 2}
\end{document}
\documentclass{article}
\pagestyle{empty}
\usepackage{lipsum}
\usepackage[top=.5in, left=.5in, right=.5in, bottom=.5in]{geometry}
\usepackage{tikz}
\usepackage{calc}
\usetikzlibrary{arrows, positioning, calc}
\tikzset{
all nodes/.style={
rounded corners=6pt,
},
small node/.style={
all nodes,
inner sep=5pt,
anchor=north west,
},
big node/.style={
all nodes,
align=center,
},
question/.style={
big node,
draw=red,
fill=red!10,
text width=.55\textwidth,
inner sep=20pt,
},
question label/.style={
small node,
draw=red,
fill=red!30,
},
hint/.style={
big node,
draw=blue,
fill=blue!10,
text width=.35\textwidth,
inner sep=5pt,
},
hint label/.style={
small node,
draw=blue,
fill=blue!30,
},
answer/.style={
big node,
align=left, % <-- added
draw=green,
fill=green!10,
text width=0.9\textwidth % <-- added
},
answer label/.style={
small node,
draw=green,
fill=green!30,
},
reset/.style={
rounded corners=0pt,
minimum height=0pt,
inner sep=.3333em,
text width=,% reset
}
}
\newlength{\nodeheighta}
\newlength{\nodeheightb}
\newcommand\WS[3]{% <-- changed 2 to 3
\sbox0{\tikz[inner sep=0pt,outer sep=0pt]{\node[question] (Question) {#1};}}%
\sbox1{\tikz[inner sep=0pt,outer sep=0pt]{\node[hint] (Hint) {#2};}}%
\setlength{\nodeheighta}{\ht0}%
\setlength{\nodeheightb}{\ht1}%
\ifdim\nodeheighta<\nodeheightb\nodeheighta=\nodeheightb\fi%
\noindent%
\begin{tikzpicture}
\node[question, minimum height=\nodeheighta,] (Question) {#1};
\node[question label] at (Question.north west) {Question};
\node[hint, minimum height=\nodeheighta, right=0pt of Question.north east, anchor=north west] (Hint) {#2};
\node[hint label] at (Hint.north west) {Hint};
\path let
\p2 = ($(Question.west)-(Hint.east)$),
\n2 = {veclen(\p2)-\pgflinewidth}, % 0.4pt is the width of the border line
\p3 = ($(Question.north)-(Question.south)$),
\n3 = {\textheight-veclen(\p3)-10.4pt}
in node[
answer,
minimum height=\n3, % <-- changed to minimum height
below=0pt of Question.south west,
anchor=north west,
minimum width=\n2
] (Answer) {#3}; % <-- added #3
% The Label
\node[answer label, anchor=north west, inner sep=5pt] at (Answer.north west) {Answer};
\end{tikzpicture}%
}
\begin{document}
\WS{Question}{Hint}{\lipsum[1]}
\end{document}
答案2
raster
此模板可轻松使用完成tcolorbox
。这样,所有关于节点大小的计算都可以通过tcolorbox
选项raster equal height=rows
和底部框用 填充可用空间自动解决height fill
。
在这种情况下,我还添加了一个顶行,其中包含可选的标题和页码。
现在命令\WS
有一个可选参数(标题)和三个必需参数,即question
盒子内容、盒子内容hint
和盒子内容answer
。
\documentclass{article}
\usepackage{lmodern}
\usepackage[most]{tcolorbox}
\usepackage{lipsum}
\usepackage[top=.5in, left=.5in, right=.5in, bottom=.5in]{geometry}
\tcbset{
mybox/.style={
enhanced,
attach boxed title to top left={yshift*=-\tcboxedtitleheight},
coltitle=black,
colframe=#1,
colback=#1!10,
boxed title style={
size=small,
colback=#1!30},
}
}
\newcommand{\WS}[4][Problem]{%
\begin{tcbitemize}[%
raster force size=false,
raster equal height=rows,
raster row skip=0pt,
raster column skip=0pt,
raster row 1/.style={
mybox=orange,
raster multicolumn=2,
notitle},
raster row 2 column 1/.style={%
mybox= red,
add to width= .05\textwidth,
title=Question},
raster row 2 column 2/.style={%
mybox= blue,
add to width= -.05\textwidth,
title=Hint},
raster row 3 column 1/.style={%
mybox= green,
raster multicolumn=2,
height fill,
title=Answer},
]
\tcbitem \textbf{#1}\hfill\thepage
\tcbitem #2
\tcbitem #3
\tcbitem #4
\end{tcbitemize}}
\pagestyle{empty}
\begin{document}
\WS{Suppose you have a right triangle as presented below. Let $a=2$ cm, and $b=3$ cm. How long would $c$ be?
{\par\centering
\begin{tikzpicture}
\draw[rounded corners=0pt] (0,0) -- (2,0) -- (2,3) -- (0,0);
\end{tikzpicture}
\par}
Remember to leave your answers as a square root, and to show all work and leave units.}%
{ \begin{itemize}
\item Think about the pythagorean formula.
\item It involves squares.
\item And adding.
\end{itemize}}{This is my answer
\lipsum[1]}
\end{document}