背景
以下屏幕截图显示了问题方案对论文来说对称的环境twoside
。
笔记:问题标题在奇数页的右侧。对于偶数页,标题在左侧。还必须考虑孤寡问题,以使标题处没有分页符。
我已经创建了这个环境,但它看起来很复杂。有没有现成的软件包可以做到这一点?
最大代码片段(我无法再最小化我的代码)
\documentclass[cmyk,10pt]{article}
\usepackage[a6paper,hmargin=1cm,vmargin=2cm]{geometry}
\usepackage{ifthen}
\usepackage{xcolor}
\usepackage{lipsum}
\usepackage{calc}
\newcounter{example}[section]
\renewcommand{\theexample}{\thesection.\arabic{example}}
\newenvironment{Example}[2][]%
{%
\refstepcounter{example}%
%------------------- Example Head -------------------
\par\nointerlineskip\vspace{\baselineskip}\noindent%
\label{example:\theexample}\color{blue}%
\ifthenelse{\isodd{\pageref{example:\theexample}}}%
{%
{\color{blue}\hrulefill}%
\raisebox{\depth}{%
\colorbox{blue}{%
\color{white}Example \theexample\ifthenelse{\equal{#1}{}}{}{\ (#1)}%
}%
}%
}
{%
\raisebox{\depth}{%
\colorbox{blue}{%
\color{white}Example \theexample\ifthenelse{\equal{#1}{}}{}{\ (#1)}%
}%
}%
{\color{blue}\hrulefill}%
}%
%------------------- Example Body -------------------
\par\nopagebreak\nointerlineskip\vspace{0.5\baselineskip}\noindent{\footnotesize#2}%
%------------------- Solution Head -------------------
\par\nointerlineskip\vspace{0.5\baselineskip}\noindent%
\colorbox{red}{\makebox[\linewidth-2\fboxsep]{\color{white}Solution}}%
%------------------- Solution Body -------------------
\par\nopagebreak\nointerlineskip\vspace{0.5\baselineskip}\noindent%
\color{red}\footnotesize\ignorespaces%
}
{%
%------------------- Solution Foot -------------------
\par\nopagebreak\nointerlineskip\vspace{0.5\baselineskip}\noindent{\color{red}\hrulefill}%
\par\nointerlineskip\vspace{\baselineskip}\noindent\ignorespacesafterend%
}
\usepackage{multido}
\begin{document}
\section{Without Title}
\begin{Example}
{%
\lipsum[1]
}%
\lipsum[2]
\end{Example}
\section{With Title}
\begin{Example}[With Title]
{%
\lipsum[1]
}%
\lipsum[2]
\end{Example}
\section{Looping}
\multido{\ix=1+1}{10}{%
\begin{Example}[\ix]
{%
\lipsum[\ix]
}%
Einstein's formula
\begin{equation}
E\not=mc^2
\end{equation}
\lipsum[\ix]
\end{Example}\lipsum[\ix]}
\end{document}
或者如果没有包,您能给我一个更好的建议吗?
答案1
相同tabularx
,但ragged2e
有一些细微的变化:
\vspace{0.5\baselineskip}
==> \medskip
\vspace{\baselineskip}
==>\bigskip
\newenvironment{Example}[2][]%
{%------------------- Example Head -------------------
\par\bigskip\noindent%
\refstepcounter{example}\label{example:\theexample}%%
\ifthenelse{\isodd{\pageref{example:\theexample}}}
{\color{blue}
\begin{tabularx}{\linewidth}{@{} >{\RaggedLeft}X @{}}
\colorbox{blue}{\color{white}Example \theexample\ifx\relax#1\relax\else~(#1)\fi}\\\hline
\end{tabularx}}
{\color{blue}
\begin{tabularx}{\linewidth}{@{} >{\RaggedRight}X @{}}%
\colorbox{blue}{\color{white}Example \theexample\ifx\relax#1\relax\else~(#1)\fi}\\\hline
\end{tabularx}}%
%------------------- Example Body -------------------
\par\nopagebreak\nointerlineskip\medskip
\noindent{\footnotesize#2}%
%------------------- Solution Head -------------------
\par\nointerlineskip\medskip\noindent%
\colorbox{red}{\makebox[\linewidth-2\fboxsep]{\color{white}Solution}}%
%------------------- Solution Body -------------------
\par\nopagebreak%\nointerlineskip\vspace{0.5\baselineskip}\noindent%
\color{red}\footnotesize\ignorespaces%
}
{%------------------- Solution Foot -------------------
\par\nopagebreak\nointerlineskip\medskip
\noindent{\color{red}\hrulefill}%
\par\nointerlineskip\bigskip\noindent\ignorespacesafterend%
}
答案2
这回忆录document 类有\ifodd
宏可以测试您是否在奇数页。您可以这样做,让章节标题根据您在奇数页还是偶数页显示不同内容。请参阅第 338 页回忆录手册
该代码改编自changepage
包,所以我想你可以使用它。