我想为书定制一个示例练习。我非常喜欢这种风格:
fbox
我认为使用和是可行的,但我不知道该怎么做。如果有其他方法,则hrule
无需使用fbox
和。hrule
编辑:底线规则在这里创建自定义规则
更新:我在 Dan 和 azetina 的帮助下编写了示例代码。非常感谢你们,现在我分享代码:
\documentclass{article}
\usepackage{multicol}
\usepackage{colortbl}
\usepackage{blindtext}
\usepackage{xcolor}
\usepackage{amsmath}
\usepackage{amssymb}
\addtolength\textwidth{2cm}
\addtolength\oddsidemargin{-1cm}
% 1. define its color
\definecolor{ejemplo}{RGB}{37,153,116}
% 2. define its counter, to be reset with each section
\newcounter{ejemplo}[section]
\renewcommand\theejemplo{\mdseries\normalsize\thesection.\arabic{ejemplo}}
% 3. define the environment. Its argument is the name of the example.
\makeatletter
\newenvironment{ejemplo}[1]{%
\bigbreak
\refstepcounter{ejemplo}
\par%
% (a) heading
\noindent{\color{ejemplo}\large\sffamily
{\setlength{\extrarowheight}{5pt}\begin{tabular}{ll@{}}%
\hline
\cellcolor{ejemplo}\color{white}%
\textmd{\normalsize Ejemplo} \theejemplo&\bfseries #1%
\end{tabular}}}\par
% (b) space after and no indentation after
\begin{multicols}{2}
\vspace{1em}%
\@afterindentfalse
\@afterheading
} {\end{multicols}
% (c) place the custom rule
\noindent{\color{ejemplo}%
\parbox{\linewidth}{%
\hrulefill\rule{2em}{0.4em}}%
}\par%
}
% The solution
\newcommand\solucion{
\par\vspace{1em}
\noindent
\colorbox{ejemplo}{\textsc{\MakeLowercase{\sffamily\mdseries\color{white}Soluci\'on}}}%
\par\vspace{1em}
\@afterindentfalse
\@afterheading
}
\makeatother
结果如下:
答案1
Ejemplo 部分看起来是用设置的colortbl
,Soluci\'on 部分是用设置的。\colorbox
下面是一些代码来产生这些效果。通常,人们会用代码编写示例\newtheorem
,并且必须付出一些努力才能实现自动化。但现在太晚了,我将留到以后再做(或者其他人可以介入)。我没有尝试匹配颜色,只是选择了蓝色。当然,人们可以根据自己的喜好更改颜色、字体和大小:
\documentclass{article}
\usepackage{colortbl}
\begin{document}
Some text.
\bigskip
\noindent{\color{blue}\Large\sffamily
\begin{tabular}{ll@{}}
\hline
\cellcolor{blue}\color{white}Ejemplo 37.12&\bfseries Choque Relativista
\end{tabular}}
\bigskip
Statement of example.
\bigskip
\noindent \colorbox{blue}{\sffamily\bfseries\color{white}SOLUCI\'ON}
\bigskip
Description of solution.
\end{document}
这是一个更完整的示例,编码为ejemplo
环境。
\documentclass{article}
\usepackage{colortbl}
\usepackage{multicol}
\usepackage{blindtext}
%
\addtolength\textwidth{2cm}
\addtolength\oddsidemargin{-1cm}
%
% Prepare an ejemplo environment
% 1. define its color
\definecolor{ejemplo}{rgb}{0.1,0.5,0.4}
% 2. define its counter, to be reset with each section
\newcounter{ejemplo}[section]
\renewcommand\theejemplo{\thesection.\arabic{ejemplo}}
% 3. Define the lengths of the rule that follows
\newlength\ejemplorulei
\newlength\ejemploruleii
\setlength\ejemploruleii{4em}
\setlength\ejemplorulei\textwidth
\addtolength\ejemplorulei{-\ejemploruleii}
% 4. define the environment. Its argument is the name of the
% example.
\makeatletter
\newenvironment{ejemplo}[1]
{%
\refstepcounter{ejemplo}
\begin{multicols}{2}%
% (a) heading
\noindent{\color{ejemplo}\large\sffamily
\begin{tabular}{ll@{}}%
\hline
\cellcolor{ejemplo}\color{white}Ejemplo \theejemplo&\bfseries #1%
\end{tabular}}\par
% (b) space after and no indentation after
\vspace{1em}%
\@afterindentfalse
\@afterheading
}{\end{multicols}
% (c) place the custom rule
\noindent{\color{ejemplo}%
\rule[2ex]{\ejemplorulei}{.4pt}%
\rule[2ex]{\ejemploruleii}{1.2pt}}\par
}
\newcommand\solucion{% The solution
\par\vspace{1em}
\noindent
\colorbox{ejemplo}{\sffamily\bfseries\color{white}SOLUCI\'ON}%
\par\vspace{1em}
\@afterindentfalse
\@afterheading
}
\makeatother
\begin{document}
\section{Start of section}
\blindtext
\begin{ejemplo}{Choque Relativista}
\blindtext[1]
\solucion
\blindtext[2]
\end{ejemplo}
\end{document}