我正在尝试执行以下操作,但不确定如何进行。我应该使用表格并使线条变粗吗?我还想让框周围的线条变蓝且变粗。我可以自动执行吗?
我已經開始這個了。
\documentclass{article}
\counterwithin{equation}{section}
\newcounter{example}
\counterwithin*{example}{section}
\newenvironment{example}[1][]{%
\stepcounter{example}%
\par\vspace{5pt}\noindent
\fbox{\textbf{Example~\theexample}}%
\hrulefill\par\vspace{10pt}\noindent\rmfamily}%
{\par\noindent\hrulefill\vrule width10pt height2pt depth2pt\par}
\usepackage{tasks}
\begin{document}
\begin{example}
\begin{tasks}
\task $(x+2)(x+3)$
\end{tasks}
\end{example}
\end{document}
编辑:抱歉造成混淆。我的文档是这样的。我试图简化它,但却让它变得更加混乱。
\documentclass[
a5paper,
% pagesize,11pt,% both are default and therefore not needed
bibliography=totoc,% bibtotoc is deprecated and therefore replaced according
% to the warning message
numbers=noenddot,% pointlessnumbers is deprecated and therefore replaced
% according to the warning message
headings=normal,% normalheadings is deprecated and therefore replaced
% according to the warning message
DIV=9,twoside=false,
headsepline,footsepline,footinclude=false,% see the KOMA-Script manual
headheight=87pt,% not used, to not lower the header, but this results in a warning
footheight=52pt, % no longer needed, because the lines are not part of the footer
]{scrbook}
\KOMAoptions{DIV=last}
\usepackage{trajan}
\usepackage{setspace}
\linespread{1.05}
\KOMAoptions{DIV=last}% moved according to the KOMA-Script manual, because it
% makes no sense before changing font an linespread.
\usepackage{graphicx}
\usepackage[%
autoenlargeheadfoot=false,% only warn but don't change height reserved for header or footer
manualmark,% or maybe automark, this is not clear due to missing information
% in the question.
plainheadsepline,plainfootsepline,% See the KOMA-Script manual for more information
]{scrlayer-scrpage}
\usepackage{geometry}
\geometry{
a5paper,
total={100mm,200mm}, %not sue what this line is either.
left=15mm,
right=15mm,
top=30mm,
bottom=35mm,
headsep=2mm,
}
\usepackage{amsmath}
\usepackage{enumitem}
\usepackage{tikz}
\usepackage{multicol,amsmath,amsfonts}
\usepackage{enumitem}
\usepackage{tasks}
\newcommand*{\answerline}[1][4cm]{\rule{0pt}{1cm}\rule{#1}{0.1mm}}
\usepackage{cancel}
\counterwithin{equation}{section}
\usepackage[table]
\newcounter{example}[section]
\newenvironment{example}[1][]{%
\setlength\fboxrule{1pt}
\refstepcounter{example}
\par\vspace{5pt}\noindent
\fcolorbox{blue}{white}{\textbf{Example~\theexample}}%
\textcolor{blue}{\hrulefill}
\par\vspace{10pt}\noindent\rmfamily}%
{\par\noindent\color{blue}\hrulefill
\vrule width10pt height2pt depth2pt\par}
\begin{document}
\begin{example}
\begin{tasks}
\task $(x+2)(x+3)$
\end{tasks}
\Large
\[
\mysquare{x}{2}{x}{x^2}{2x}{3}{3x}{6}
\]
\end{example}
\end{document}
答案1
有很多方法可以做到这一点,包括更复杂和更简单的包以及更复杂和更简单的自定义配置。下面是一个使用efbox
、makecell
和 的示例xcolor
。
如果您想要排版许多具有类似格式的示例,则可以创建自定义宏或环境以避免重复代码。您还可以使用efbox
and/or提供的配置命令makecell
。我在这里展示了一个示例,其中表格标题的对齐方式是全局配置的,但这可能不是您情况下最合理的做法。
无论其他考虑如何,我建议使用\efboxsetup{}
来配置标准设置并执行类似操作,makecell
以确保一致性并易于更改格式。
\documentclass{article}
\usepackage{xcolor}
\usepackage{efbox}
\usepackage{makecell}
\usepackage{tasks}
\counterwithin{equation}{section}
\newcounter{example}
\counterwithin*{example}{section}
\newenvironment{example}[1][]{%
\stepcounter{example}%
\par\vspace{5pt}\noindent
\efbox[font=\normalfont\bfseries,linecolor=cyan,linewidth=.6pt]{Example~\theexample}%
{\color{cyan}\hrulefill}\par\vspace{10pt}\noindent\rmfamily}%
{\par\noindent{\color{cyan}\hrulefill\vrule width10pt height2pt depth2pt}\par}
\setcellgapes{5pt}
\newcolumntype{C}{>{\color{black}}c}
\renewcommand\theadalign{CCC}
\begin{document}
\begin{example}
\begin{tasks}
\task $(x+2)(x+3)$
\begin{center}
\color{red}
\begin{tabular}{%
*{3}{!{\vrule width 1pt}C}!{\vrule width 1pt}
}
\Xcline{2-3}{1pt}
\multicolumn{1}{c!{\vrule width 1pt}}{\thead{$\times$}} & \thead{$x$} & \thead{$2$} \\\Xhline{1pt}
\thead{$x$} & $x^{2}$ & $2x$ \\\Xhline{1pt}
\thead{$3$} & $3x$ & $6$ \\\Xhline{1pt}
\end{tabular}
\end{center}
\end{tasks}
\end{example}
\end{document}
上述代码产生的输出与目标图像非常相似,突出cyan
显示任务并red
突出显示答案。在标题等的标准配置makecell
中启用间隙单元格。tabular
编辑
为了回答评论中的后续问题,您可以通过替换\hrulefill
合适的来调整线条的宽度\vrule
。为此,我们创建了一些变量来保存长度和一个框,这样我们就可以测量而\efbox
无需排版两次。
\documentclass{article}
\usepackage{xcolor}
\usepackage{efbox}
\usepackage{makecell}
\usepackage{tasks}
\counterwithin{equation}{section}
\newcounter{example}
\counterwithin*{example}{section}
\newlength \templgtha
\newlength \templgthb
\newlength \templgthc
\newsavebox \tempboxa
\setlength \templgthb {\textwidth}
\setlength \templgthc {\textwidth}
\addtolength \templgthc {-10pt}
\newenvironment{example}{%
\stepcounter{example}%
\par\vspace{5pt}\noindent
\sbox \tempboxa{%
\efbox[font=\normalfont\bfseries,linecolor=cyan,linewidth=.6pt]{Example~\theexample}%
}%
\settowidth \templgtha {\usebox \tempboxa}%
\addtolength \templgthb {-\templgtha}%
\usebox \tempboxa
{\color{cyan}\vrule width\templgthb height0.3pt depth0.3pt}\par\vspace{10pt}\noindent\rmfamily
}{%
\par\noindent
{%
\color{cyan}%
\vrule width\templgthc height0.3pt depth0.3pt
\vrule width10pt height2pt depth2pt
}\par
}
\setcellgapes{5pt}
\newcolumntype{C}{>{\color{black}}c}
\renewcommand\theadalign{CCC}
\begin{document}
\begin{example}
\begin{tasks}
\task $(x+2)(x+3)$
\begin{center}
\color{red}
\begin{tabular}{%
*{3}{!{\vrule width 1pt}C}!{\vrule width 1pt}
}
\Xcline{2-3}{1pt}
\multicolumn{1}{c!{\vrule width 1pt}}{\thead{$\times$}} & \thead{$x$} & \thead{$2$} \\\Xhline{1pt}
\thead{$x$} & $x^{2}$ & $2x$ \\\Xhline{1pt}
\thead{$3$} & $3x$ & $6$ \\\Xhline{1pt}
\end{tabular}
\end{center}
\end{tasks}
\end{example}
\end{document}
输出看起来与上图一样,只是水平青色规则的宽度现在是0.6pt
( 0.3pt
+ 0.3pt
),而不是使用默认线宽。这与用于的规则的宽度相匹配,\efbox
并且可能应该与这些设置同步调整。也就是说,如果您使用0.8pt
框,您可能需要0.4pt
规则的高度和深度等。
答案2
像这样吗?
\documentclass{article}
\counterwithin{equation}{section}
\usepackage{tasks}
\usepackage[table]{xcolor}
\newcounter{example}[section]
\newenvironment{example}[1][]{%
\setlength\fboxrule{1pt}
\refstepcounter{example}
\par\vspace{5pt}\noindent
\fcolorbox{blue}{white}{\textbf{Example~\theexample}}%
\textcolor{blue}{\hrulefill}
\par\vspace{10pt}\noindent\rmfamily}%
{\par\noindent\color{blue}\hrulefill
\vrule width10pt height2pt depth2pt\par}
\newcommand\mysquare[8]{%
\arrayrulecolor{red}
\setlength\arrayrulewidth{2pt} % set line thickness
\renewcommand\arraystretch{2}
\begin{array}{|*{3}{wc{1cm}|}} % fixed-width columns
\cline{2-3}
\multicolumn{1}{c|}{\times} & #1 & #2 \\
\hline
#3 & #4 & #5 \\
\hline
#6 & #7 & #8 \\
\hline
\end{array}}
\begin{document}
\begin{example}
\begin{tasks}
\task $(x+2)(x+3)$
\end{tasks}
\Large
\[
\mysquare{x}{2}{x}{x^2}{2x}{3}{3x}{6}
\]
\end{example}
\end{document}