如何定义界限内的悬挂部分

如何定义界限内的悬挂部分

我想定义/创建一个与紧随其后的第一段相关的悬挂小节(在界限内);也就是说,整个段落缩进。我试图在这个 MWE 中提供我的梦想的图片/展示。我的梦想有可能实现吗?

\documentclass[10pt]{book}
%%==============================================================================
\usepackage{etoolbox}
\usepackage{enumitem}
\usepackage{amsmath,amsthm}
\usepackage{kantlipsum}
%%-----------------------------------------------------------------------------
\makeatletter
\newcommand\qsection{\suppressfloats[t]\@startsection% floats not to move backwards          
           {section}%                               % name
           {1}%                                     % level--section heading
           {0pt}%                                   % no indentation from left margin
           {-1.0\baselineskip minus\parskip}%       % beforeskip--suppress par indentation
           {0.5\baselineskip}%                      % afterskip--display heading
           {\normalfont\large\bfseries\raggedright}}% style
%%------------------------------------------------------------------------------
\newcommand\qsubsection{\@startsection
           {subsection}%                            % name
           {2}%                                     % level--subsection heading
           {0pt}%                                   % no indentation from left margin
           {-0.5\baselineskip plus0.2\baselineskip minus0.2\baselineskip}%
           {-0.10ex}%                               % afterskip (run-in)
           {\normalfont\bfseries\raggedright}}%     % style
\makeatother
%%------------------------------------------------------------------------------
\renewcommand\thesection{\Alph{section}.}
\renewcommand\thesubsection{\arabic{subsection}.}
%%------------------------------------------------------------------------------
%%  special theoremstyle environment for trial subsection definition
%%------------------------------------------------------------------------------
\newtheoremstyle{fakesub}
{0.5\baselineskip plus0.2\baselineskip minus0.2\baselineskip}%
{0pt}%
{\normalfont}%
{0pt}%
{\bfseries}%
{}%
{0em}%
{\llap{\makebox[\defsep][l]{%
    \thmname{#1}~\thmnumber{#2}\if\relax\detokenize{#3}\relax.\fi}}%
    \thmnote{~{\normalfont(#3)}}}
%%------------------------------------------------------------------------------
\theoremstyle{fakesub}
\newtheorem{defn}{Definition}[chapter]
\newtheorem{fakesubsection}[defn]{\!\!}% ``fake'' subsection definition
%%------------------------------------------------------------------------------
\newlength\defsep
\setlength{\defsep}{4.5ex}%
%%
\makeatletter
\AtBeginEnvironment{fakesubsection}{%
    \refstepcounter{subsection}
    \renewcommand\thedefn{\arabic{subsection}}
    \patchcmd{\@thm}{\trivlist}{\list{}{\leftmargin=\defsep}}{}{}
    \patchcmd{\@endtheorem}{\endtrivlist}{\endlist}{}{}
}
\makeatother
%%------------------------------------------------------------------------------
\newcommand*{\fmap}[1]{\ensuremath{#1\mkern1mu\textnormal{:}}\;}

\begin{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\chapter{Abelian Groups}
%%------------------------------------------------------------------------------
I would like to define a subsection to look like a hang section (within bounds) with respect to the first paragraph following the subsection; that is, the whole paragraph be indented. I prefer the ``fake'' subsection is $\mathbf{1}$\textbf{.} under section~\textbf{\ref{02VectorSpaces}} to that of the ``real'' one under section~\textbf{\ref{01VectorSpaces}} ...
%%------------------------------------------------------------------------------
\qsection{Vector Spaces}\label{01VectorSpaces}
%%--------
My aim is to make this ``real'' subsection $\mathbf{1}$\textbf{.} to display like the ``fake'' one under section~\textbf{\ref{02VectorSpaces}}.
\qsubsection{}\label{01RealSubsection}
Two vector spaces are \emph{isomorphic} if there is a bijection $\fmap{\varphi}L\to L'$ such that $\varphi(\lambda{a} +\mu{b}) = \lambda\varphi(a)+\mu\varphi(b)$ for all $\lambda$, $\mu$, $a$ and $b$; that is, $\varphi$ preserves the operations of addition and multiplication.
%%------------------------------------------------------------------------------
\qsection{Vector Spaces}\label{02VectorSpaces}
%%--------
This is ``fake'' subsection $\mathbf{1}$\textbf{.} under section~\textbf{\ref{02VectorSpaces}}  ...
\begin{fakesubsection}\label{01FakeSubsection}
Two vector spaces are \emph{isomorphic} if there is a bijection $\fmap{\varphi}L\to L'$ such that $\varphi(\lambda{a} +\mu{b}) = \lambda\varphi(a)+\mu\varphi(b)$ for all $\lambda$, $\mu$, $a$ and $b$; that is, $\varphi$ preserves the operations of addition and multiplication. %(Second and subsequent paragraphs after the ``fake'' subsection are displayed in normal fashion.)
\end{fakesubsection}
%%------------------------------------------------------------------------------
\end{document}
%%==============================================================================

答案1

我使用定制的枚举方法(Bernard 的建议)来回答这个问题。我希望以下 MWE 能够足够清楚地表达我提出这个问题的初衷。

%%-------------------------------------------------------------------
%% a hang subsection within margins using a custom enumerate
%%--------------------------------------------------------------------
\documentclass[10pt]{book}
%%--------------------------
\usepackage{amsmath,amsthm}
\usepackage{enumitem}
\usepackage{xparse}

\makeatletter
\newcommand\qsection{\suppressfloats[t]\@startsection%
           {section}%
           {1}%
           {0pt}%
           {-1.0\baselineskip minus\parskip}%
           {0.5\baselineskip minus\parskip}%
           {\normalfont\large\bfseries\raggedright}}%
\makeatother
\renewcommand\thesection{\Alph{section}.}
%%-------------------------------------------------------------------
\newlength{\hangwidth}  \newlength\afterskip
%%-------------------------------------------------------------------
\ExplSyntaxOn
\NewDocumentEnvironment{hsubsection}{O{} O{.5} O{}}%
{%%
 \setlength{\afterskip}{-#2\baselineskip}
 \renewcommand\thesubsection{\arabic{subsection}}
%%------------
 \tl_if_empty:nTF{#1}%    
        {%                        %% no title header
          \refstepcounter{subsection}
          \settowidth{\hangwidth}{\bfseries\thesubsection.}
          \def\hanglabel{\bfseries\thesubsection.}
        }
        {%
          \tl_if_empty:nTF{#3}% 
                 {%               %% unnumbered title header
                   \settowidth{\hangwidth}{\bfseries#1}
                   \def\hanglabel{\bfseries#1}
                 }
                 {%               %% numbered title header
                   \refstepcounter{subsection}
                   \settowidth{\hangwidth}{\bfseries\thesubsection\hspace{.5em}#1}
                   \def\hanglabel{\bfseries\thesubsection\hspace{.5em}#1}
                 }
        }
%%-------------------------------------------------------------------
 \begin{hangSubsection}
 \item
}
{%
 \end{hangSubsection}
 \vspace{\afterskip}
 \par%
}
\ExplSyntaxOff
%%-------------------------------------------------------------------
\newlist{hangSubsection}{enumerate}{1}%
%%--------------------------------
\setlist[hangSubsection]{%
  label=\hanglabel,
  ref=\thesubsection,
  align=left,
  leftmargin={\dimexpr \hangwidth + 1.0em},
  labelwidth=*,
  topsep=1\baselineskip plus0.2\baselineskip minus0.2\baselineskip,
  itemsep=0pt,
  before=\normalfont\normalsize
}
%%-------------------------------------------------------------------
\newcommand*{\fmap}[1]{\ensuremath{#1\mkern1mu\textnormal{:}}\;}
%%===================================================================
\begin{document}
%%-------------------------------------------------------------------
\chapter{Abelian Groups}
%%----------------------
An attempt to define a hang subsection with the first paragraph following it all indented, and within the boundaries of the left and right margins.
%%
\qsection{Vector Spaces}\label{01VectorSpaces}
We will attempt to show hang subsections with no title header, with unnumbered short title header, and with numbered short title header.\par%
It may be prudent to use the normal ``display'' or ``run-in'' sectioning definitions for for subsections with long title headers.
\begin{hsubsection}[][.7]\label{01FakeSubsection}
Two vector spaces are \emph{isomorphic} if there is a bijection $\fmap{\varphi}L\to L'$ such that $\varphi(\lambda{a} +\mu{b}) = \lambda\varphi(a)+\mu\varphi(b)$ for all $\lambda$, $\mu$, $a$ and $b$; that is, $\varphi$ preserves the operations of addition and multiplication.
\end{hsubsection}

下一节带有未编号的短标题标题:

%%
\begin{hsubsection}[Claim][.7]\label{02FakeSubsection}
Two vector spaces are \emph{isomorphic} if there is a bijection $\fmap{\varphi}L\to L'$ such that $\varphi(\lambda{a} +\mu{b}) = \lambda\varphi(a)+\mu\varphi(b)$ for all $\lambda$, $\mu$, $a$ and $b$; that is, $\varphi$ preserves the operations of addition and multiplication.
\end{hsubsection}

这是另一个没有标题标题的编号小节……

\begin{hsubsection}\label{03FakeSubsection}
Two vector spaces are \emph{isomorphic} if there is a bijection $\fmap{\varphi}L\to L'$ such that $\varphi(\lambda{a} +\mu{b}) = \lambda\varphi(a)+\mu\varphi(b)$ for all $\lambda$, $\mu$, $a$ and $b$; that is, $\varphi$ preserves the operations of addition and multiplication.
\end{hsubsection}

这是一个带有简短标题标题的编号小节...

%%
\begin{hsubsection}[Claim][.7][Yes]\label{04FakeSubsection}
Two vector spaces are \emph{isomorphic} if there is a bijection $\fmap{\varphi}L\to L'$ such that $\varphi(\lambda{a} +\mu{b}) = \lambda\varphi(a)+\mu\varphi(b)$ for all $\lambda$, $\mu$, $a$ and $b$; that is, $\varphi$ preserves the operations of addition and multiplication.
\end{hsubsection}
\end{document}

相关内容