我可以将 adjustwidth 用到我的目的吗?

我可以将 adjustwidth 用到我的目的吗?

我想排版一些带有水平缩进的内容。例如,在(一个案例(二)案件(橙色区域)。我首先尝试了{\leftskip 2em ...},但这只会影响文字,既不影响表格也不影响数字。而且 minipage 对我来说也不理想,因为我希望它可以在需要时翻页。

因此我尝试了adjustwidth(包changepage在此处输入图片描述

问题

  1. 使用adjustwidth环境是否适合我的目的?还有其他更好的解决方案吗?
  2. 为什么环境中的左边距adjustwidth没有像我预期的那样直接向右移动到 2em(即,我预期 (i) 位于“D”的正下方,如上所示)?

代码:

\documentclass[12pt,a4paper,openany,fleqn]{book}
\usepackage[margin=2cm, top=2cm]{geometry}
\usepackage{amsmath}
\usepackage[no-math]{fontspec}
\usepackage[fancyhdr,noindent]{ctexcap}
\usepackage{xeCJK}
\setCJKmainfont{Times New Roman}
\linespread{1.6}
\parindent = 0 pt
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}}


\CTEXsetup[format={\large},beforeskip={3.5ex},afterskip={0.3ex plus 0.1ex},aftername={}]{section}
\renewcommand{\thesection}{(\arabic{section})~}


\newcommand{\allindent}{\hangindent = 2em\hangafter = 0}
\newcommand{\doubleindent}{\hangindent = 4em\hangafter = 0}

\newcounter{iItemcounter}
\newcommand{\iItem}[2][4em]{
    \setcounter{iItemcounter}{0}
    \begin{list}{(\roman{iItemcounter})}{\usecounter{iItemcounter}\itemsep=0pt\parsep=0pt\parskip=0pt\topsep=0pt
    \leftmargin = #1}{#2}\end{list}
}

\newcommand{\discussItem}[1]{
    \par\allindent \textbf{Discuss:}
    \iItem{#1}
}

\usepackage{changepage}
\begin{document}
\section{Section Title:}
\allindent
This is level one.
\discussItem{\item discuss something
\item discuss something}

\allindent
Now we gonna think of some case. Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah\\
\textbf{(a)Case $a>1$:}
\begin{adjustwidth}{4em}{}
In this case, we know that blah blah blah. (Here may have many words, tables or figures.)\\
Some table: \begin{tabular}[t]{lll}
(1)~$a^m\cdot a^n=a^{m+n}$&(2)~$\frac{a^m}{a^n}=a^{m-n}$\quad($m>n,~a\neq 0$)  &(3)~$(a^m)^n=a^{mn}$  \\
(4)~$(ab)^n=a^n\cdot b^n$   &(5)~$\left(\frac{a}{b}\right)^n=\frac{a^n}{b^n}$\quad($b\neq 0$)  &
\end{tabular}

\discussItem{\item Here the position of item is not the same as above, why?}
\end{adjustwidth}

\allindent \textbf{(b)Case $a<1$:}

\doubleindent Some words. Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah .
\end{document}

答案1

我可以提出这个建议。由于我不太清楚你想要什么,我希望它接近你想要的。

首先,我没有使用第一个\hangindent。相反,我增加了左边距(约2 em),并将章节编号与包一起放入边距中titlesec

接下来我使用了的功能enumitem,特别是resume功能(停止枚举环境并稍后使用相同的布局参数恢复它)和概念series(共享通用格式和计数器的环境)。

最后,我\thesection 以正确的方式重新定义,这在交叉引用中没有副作用。您想要给出的内容在命令中获得\titleformat。我用环境替换了手动编号的水平列表tasks,并带有自动编号。您可以在这些软件包的文档中找到详细信息。

\documentclass[12pt,a4paper,openany,fleqn]{book}
\usepackage[margin=2.8cm, top=2cm, showframe]{geometry}
\usepackage{amsmath}
\usepackage[no-math]{fontspec}
%\usepackage[fancyhdr,noindent]{ctexcap}
%\usepackage{xeCJK}
%\setCJKmainfont{Times New Roman}
\setmainfont{Times New Roman}
\linespread{1.6}
\parindent = 0 pt
\usepackage{fancyhdr}
\pagestyle{fancy}
\fancyhf{}
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}
\fancypagestyle{plain}{%
\fancyhf{} % clear all header and footer fields
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt}
\renewcommand{\footrulewidth}{0pt}}


%\CTEXsetup[format={\large},beforeskip={3.5ex},afterskip={0.3ex plus 0.1ex},aftername={}]{section}
 \usepackage{changepage}
\usepackage{enumitem, tasks}
\usepackage{titlesec}
\usepackage{bm}
\renewcommand{\thesection}{\arabic{section}}
\makeatletter
\titleformat{\section}[hang]{\normalfont\Large\bfseries}{(\thesection)}{1em}{}
\titlespacing{\section}{-2em} {-3.5ex \@plus -1ex \@minus -.2ex}{2.3ex \@plus.2ex}%
\makeatother

\begin{document}

\section{Section Title:}

\begin{enumerate}[label =(\roman*), leftmargin =2em, nosep, before =\textbf{Discuss}]
  \item discuss something
  \item discuss something
\end{enumerate}
Now we gonna think of some case. Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah\\
\begin{enumerate}[label =(\alph*), font =\bfseries, wide=0pt, leftmargin=2em, labelsep =* , nosep, before =\textbf{Discuss}, series=cases]
  \item \textbf{Case $ \bm{a > 1} $: }

  In this case, we know that blah blah blah. (Here may have many words, tables or figures.)

Some table:
\begin{tasks}[counter-format =(tsk[1]), item-indent =0em, label-offset=0.5em](3)
\task $a^m · a^n=a^{m+n}$
\task* $\dfrac{a^m}{a^n}=a^{m-n}$\quad ($m>n,~a ≠ 0$)
\task $(a^m)^n=a^{mn}$
\task $(ab)^n=a^n · b^n$
\task $\left(\dfrac{a}{b}\right)^n=\dfrac{a^n}{b^n}$\quad($b ≠ 0$)
\end{tasks}
\end{enumerate}
\begin{enumerate}[label =(\roman*), leftmargin =2em, nosep, before =\textbf{Discuss}]
  \item Here the position of item is not the same as above, why?
\end{enumerate}

\begin{enumerate}[resume*=cases, before = \relax]
\item \textbf{Case $\bm{a<1}$:}

Some words. Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah Blah.
\end{enumerate}

\end{document} 

在此处输入图片描述

相关内容