在这个 MWE 中,我希望始终让\blacksquare
框出现在页面的右侧并位于文本最后一行的下方一行。
这是我的代码:
\documentclass[11pt]{book}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{mathtools,amsfonts,amssymb,amsthm}
\usepackage{graphicx}
\definecolor{ocre}{RGB}{52,177,201}
\newcommand{\newqed}{{\hfill\color{ocre}\ensuremath{\blacksquare}}}
\begin{document}
\chapter{Problems from Chapter 2}
\section{Problem 2.4}\index{Problem 2.4}
\subsection{Problem 2.4}
Line 1: This is just some test text. This is just some test text. This is.
\newqed
\subsection{Solution 2.4}\index{Solution 2.4}
Line 2: This is just some test text. This is just some test text. This is just.
\newqed
\end{document}
答案1
该amsthm
软件包已经提供了基础设施:
\documentclass[11pt]{book}
\usepackage[english]{babel}
\usepackage{lipsum}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage{mathtools,amsfonts,amssymb,amsthm}
\usepackage{graphicx}
\definecolor{ocre}{RGB}{52,177,201}
\renewcommand{\qedsymbol}{\textcolor{ocre}{$\blacksquare$}}
\begin{document}
\chapter{Problems from Chapter 2}
\section{Problem 2.4}\index{Problem 2.4}
\subsection{Problem 2.4}
Line 1: This is just some test text. This is just some test text. This is.\qed
\subsection{Solution 2.4}\index{Solution 2.4}
Line 2: This is just some test text. This is just some test text. This is just.\qed
\end{document}
答案2
您必须\null
在前面添加,\hfill
因为\hfill
是可移动项目。您的段落以以下内容结尾:
...text.<space>\hfill<square>\parfillskip\par
如果段落在空格处中断,则后面的可删除项(即\hfill
)将被删除,并且下一行将<square>\parfillskip
放在square
左侧。但如果\null
(即空框)在之前\hfill
,则下一行在表格中\null\hfill<square>\parfillskip
,这会将 放在<square>
右侧,因为\parfillskip
只是0pt plus 1fil
默认情况下。
你的宏如下所示:
\def\newqed{{\null\nobreak\hfill\color{ocre}\ensuremath{\blacksquare}}}