总是在页面右侧显示 \blacksquare 框

总是在页面右侧显示 \blacksquare 框

在这个 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}}}

相关内容