雾月
雾月
这家伙很懒,什么也没写!

注册于 3年前

回答
184
文章
2
关注者
19

更新:

我 fork 了一份,增加了简单的解析功能,https://github.com/Sophanatprime/Polynomial-division

\PolySet{a}{1,-12,0,-42}
\PolySet{b}{1,-3}
$ \PolyLongDiv{a}{b} $
\quad
\PolySet{a}{1,-4,6,-4}
\PolySet{b}{1,-2}
$ \PolyLongDiv{a}{b} $

\PolySet*{a}{x^3-12x^2-42}
\PolySet*{b}{x-3}
$ \PolyLongDiv{a}{b} $\quad
$ \PolyLongDiv*[stage=4]{x^3-12x^2-42}{x-3} $

$ \PolyLongDiv*{-4x^2+x^3+6x-4x^0}{-2+x} $\quad
$ \PolyLongDiv*[var=y]{y^3-3y^2+3y-1}{y-1} $

$ \PolyPrint*{-4x^2+x^3+6x-4x^0} $

\PolySet{p}{1,0,1,1}
\PolySet{q}{2,1}
\PolySet{r}{1,0,1,0}

$ \PolyLongDiv[base=3]{r}{q} \quad \PolyLongDiv[base=3]{p}{q} $

https://github.com/loopspace/Polynomial-division 的基础上,判断最高次系数是否为负,而不是将 \l__poly_uline_tl 直接修改:
image.png

\documentclass{article}
%\url{http://tex.stackexchange.com/q/79411/86}
%\RequirePackage{xparse,expl3}
\ExplSyntaxOn
\bool_new:N \l__poly_zeros_bool
\bool_new:N \l__poly_first_bool
\bool_new:N \l__poly_trailing_bool
\bool_new:N \l__poly_ptrailing_bool
\bool_new:N \l__poly_stage_bool
\bool_new:N \l__poly_mod_bool
\bool_set_true:N \l__poly_stage_bool
\tl_new:N \l__poly_var_tl
\tl_new:N \l__poly_sep_tl
\tl_new:N \l__poly_longdiv_sep_tl
\tl_new:N \l__poly_oline_tl
\tl_new:N \l__poly_uline_tl
\tl_new:N \l__poly_neguline_tl
\tl_set:Nn \l__poly_var_tl {x}
\tl_set:Nn \l__poly_sep_tl {}
\tl_set:Nn \l__poly_longdiv_sep_tl {}
\int_new:N \l__poly_deg_int
\int_new:N \l__poly_pad_int
\int_new:N \l__poly_base_int
\int_new:N \l__poly_tmpa_int
\int_new:N \l__poly_tmpb_int
\int_new:N \l__poly_mod_tmpa_int
\int_new:N \l__poly_mod_tmpb_int
\int_new:N \l__poly_mod_tmpc_int
\int_new:N \l__poly_mod_tmpd_int
\int_new:N \l__poly_trailing_int
\int_new:N \l__poly_stage_int
\int_new:N \l__poly_cstage_int
\int_set:Nn \l__poly_pad_int{3}
\seq_new:N \l__poly_gtmpa_seq
\seq_new:N \l__poly_mod_seq

\keys_define:nn { polynomial }
{
  stage .code:n = {
    \bool_set_false:N \l__poly_stage_bool
    \int_set:Nn \l__poly_stage_int {#1}
  },
  base .code:n = {
    \bool_set_true:N \l__poly_mod_bool
    \int_set:Nn \l__poly_base_int {#1}
    \cs_set_eq:NN \poly_int_div:Nnn \poly_mod_int_div:Nnn
  },
  zeros .bool_set:N = \l__poly_zeros_bool,
  separator .tl_set:N = \l__poly_sep_tl,
  variable .tl_set:N = \l__poly_var_tl,
  var .tl_set:N = \l__poly_var_tl,
%  trailing .bool_set:N = \l__poly_trailing_bool
}

\cs_new_nopar:Npn \poly_print:N #1 {
  \int_gset:Nn \l__poly_deg_int {\seq_count:N #1}
  \int_gdecr:N \l__poly_deg_int
  \int_gset:Nn \l__poly_tmpa_int {\l__poly_deg_int -
    \l__poly_trailing_int+1}
  \bool_gset_eq:NN \l__poly_ptrailing_bool \l__poly_trailing_bool
  \bool_gset_true:N \l__poly_first_bool
  \int_compare:nT {\l__poly_deg_int < \l__poly_pad_int} {
    \prg_replicate:nn {2*(\l__poly_pad_int -
      \l__poly_deg_int)}{\tl_use:N \l__poly_sep_tl}
  }
  \seq_map_inline:Nn #1 {
    \bool_if:nTF {\int_compare_p:n {##1 == 0} && \l__poly_first_bool}
    {
      \tl_use:N \l__poly_sep_tl
      \int_compare:nT {\l__poly_deg_int == 0}{0}
      \tl_use:N \l__poly_sep_tl
    }
    {
      \bool_if:nTF {\int_compare_p:n {##1 != 0} || \l__poly_zeros_bool}
      {
    \int_compare:nTF {##1 < 0} 
    {
          \bool_if:NF \l__poly_first_bool {
        \tl_use:N \l__poly_sep_tl
          }
          - \tl_use:N \l__poly_sep_tl
      \bool_if:nF {\int_compare_p:n {##1 == -1} && \int_compare_p:n {\l__poly_deg_int > 0}}
      {
        \int_eval:n {-##1}
      }
    }
    {
      \bool_if:NF \l__poly_first_bool {\tl_use:N \l__poly_sep_tl+} \tl_use:N \l__poly_sep_tl
      \bool_if:nF {\int_compare_p:n {##1 == 1} && \int_compare_p:n {\l__poly_deg_int > 0}}
      {
        ##1
      }
    }
    \int_compare:nT {\l__poly_deg_int > 0}
    {
      \tl_use:N \l__poly_var_tl
      \int_compare:nT {\l__poly_deg_int > 1} {^{\int_use:N \l__poly_deg_int}}
    }
      }
      {
    \tl_use:N \l__poly_sep_tl
    \tl_use:N \l__poly_sep_tl
      }
      \bool_gset_false:N \l__poly_first_bool
    }
    \int_gdecr:N \l__poly_deg_int
    \bool_if:nT {\l__poly_ptrailing_bool && \int_compare_p:n {\l__poly_deg_int < \l__poly_tmpa_int}} {
      \seq_map_break:
    }
  }
}
\cs_generate_variant:Nn \poly_print:N {c}

\cs_new_nopar:Npn \poly_reduce_mod:N #1 {
  \bool_if:NT \l__poly_mod_bool
  {
    \seq_clear_new:N \l__poly_mod_seq
    \int_step_inline:nnnn {1} {1} {\seq_count:N #1} {
      \seq_put_left:Nx \l__poly_mod_seq {\int_mod:nn {\int_mod:nn {\seq_item:Nn #1 { - ##1}+0} {\l__poly_base_int} + \l__poly_base_int}{\l__poly_base_int}}
    }
    \seq_set_eq:NN #1 \l__poly_mod_seq
  }
}

\cs_new_nopar:Npn \poly_add:NNN #1#2#3 {
  \seq_clear_new:N #1
  \int_step_inline:nnnn {1} {1} {\int_max:nn {\seq_count:N #2} {\seq_count:N #3}} {
    \seq_put_left:Nx #1 {\int_eval:n {\seq_item:Nn #2 { - ##1} + \seq_item:Nn #3 { - ##1}+0}}
  }
  \poly_reduce_mod:N #1
}
\cs_generate_variant:Nn \poly_add:NNN {Ncc,ccc}

\cs_new_nopar:Npn \poly_sub:NNN #1#2#3 {
  \seq_clear_new:N #1
  \int_step_inline:nnnn {1} {1} {\int_max:nn {\seq_count:N #2} {\seq_count:N #3}} {
    \seq_put_left:Nx #1 {\int_eval:n {\seq_item:Nn #2 { - ##1} - \seq_item:Nn #3 { - ##1}+0}}
  }
  \poly_reduce_mod:N #1
}
\cs_generate_variant:Nn \poly_sub:NNN {Ncc,ccc}
\cs_new_nopar:Npn \poly_shift:Nn #1#2 {
  \prg_replicate:nn {#2} {
    \seq_put_right:Nn #1 {0}
  }
}
\cs_new_nopar:Npn \poly_mul:NNN #1#2#3 {
  \seq_clear_new:N #1
  \group_begin:
  \seq_clear_new:N \l__poly_tmpa_seq    
  \seq_clear_new:N \l__poly_tmpb_seq    
  \seq_clear_new:N \l__poly_tmpc_seq    
  \int_set:Nn \l__poly_tmpa_int {\seq_count:N #2 - 1}
  \seq_map_inline:Nn #2 {
    \seq_clear:N \l__poly_tmpa_seq
    \seq_map_inline:Nn #3 {
      \seq_put_right:Nx \l__poly_tmpa_seq {\int_eval:n {##1 * ####1}}
    }
    \poly_shift:Nn \l__poly_tmpa_seq {\l__poly_tmpa_int}
    \poly_add:NNN \l__poly_tmpc_seq \l__poly_tmpb_seq \l__poly_tmpa_seq
    \seq_set_eq:NN \l__poly_tmpb_seq \l__poly_tmpc_seq
    \int_decr:N \l__poly_tmpa_int
  }
  \seq_gset_eq:NN \l__poly_gtmpa_seq \l__poly_tmpb_seq
  \group_end:
  \seq_set_eq:NN #1 \l__poly_gtmpa_seq
  \seq_clear:N \l__poly_gtmpa_seq
  \poly_reduce_mod:N #1
}
\cs_generate_variant:Nn \poly_mul:NNN {Ncc, ccc}

\cs_new_nopar:Npn \poly_int_div:Nnn #1#2#3
{
  \int_set:Nn #1 {#2 / #3}
}

\cs_new_nopar:Npn \poly_mod_int_div:Nnn #1#2#3
{
  \int_zero:N \l__poly_mod_tmpa_int
  \int_set_eq:NN \l__poly_mod_tmpb_int #2
  \int_set:Nn \l__poly_mod_tmpc_int { \l__poly_base_int - #3 }
  \bool_while_do:nn {
    \int_compare_p:n { \l__poly_mod_tmpa_int < \l__poly_base_int }
    &&
    \int_compare_p:n {\l__poly_mod_tmpb_int != 0 }
  }
  {
    \int_incr:N \l__poly_mod_tmpa_int
    \int_set:Nn \l__poly_mod_tmpb_int {
      \int_mod:nn { \l__poly_mod_tmpb_int + \l__poly_mod_tmpc_int }
      { \l__poly_base_int }
    }
  }
    
  \int_set_eq:NN #1 \l__poly_mod_tmpa_int
}

\cs_new_nopar:Npn \poly_div:NNN #1#2#3 {
  \seq_clear_new:N #1
  \poly_int_div:Nnn \l__poly_tmpa_int {\seq_item:Nn #2 {1} } { \seq_item:Nn #3 {1}}
  \seq_put_left:NV #1 \l__poly_tmpa_int
  \poly_shift:Nn #1 {\seq_count:N #2 - \seq_count:N #3}
  \poly_reduce_mod:N #1
}
\cs_generate_variant:Nn \poly_div:NNN {Ncc, ccc}
\prg_new_conditional:Npnn \poly_is_divisible:NN #1#2 {p,T,F,TF} {
  \int_compare:nTF {\seq_count:N #1 < \seq_count:N #2}
  {
    \prg_return_false:
  }
  {
    \prg_return_true:
  }
}
\cs_new_nopar:Npn \poly_trim:N #1 {
  \bool_do_while:nn {
    \int_compare_p:n {\seq_count:N #1 > 1}
    &&
    \int_compare_p:n {\seq_item:Nn #1 {1} == 0}
  } {
    \seq_pop_left:NN #1 \l_tmpa_tl
  }
}
\cs_new_nopar:Npn \poly_longdiv:NN #1#2 {
  \group_begin:
  \seq_clear_new:N \l__poly_quotient_seq
  \seq_clear_new:N \l__poly_remainder_seq
  \seq_clear_new:N \l__poly_factor_seq
  \seq_set_eq:NN \l__poly_remainder_seq #1
  \seq_clear_new:N \l__poly_lines_seq
  \int_zero:N \l__poly_cstage_int
  \bool_do_while:nn {
    \poly_is_divisible_p:NN \l__poly_remainder_seq #2
    &&
    (\l__poly_stage_bool || \int_compare_p:n {\l__poly_stage_int > \l__poly_cstage_int})
  }
  {
    \poly_div:NNN \l__poly_factor_seq \l__poly_remainder_seq #2
    \poly_add:NNN \l__poly_tmpa_seq \l__poly_factor_seq \l__poly_quotient_seq
    \seq_set_eq:NN \l__poly_quotient_seq \l__poly_tmpa_seq
    \poly_mul:NNN \l__poly_tmpa_seq \l__poly_factor_seq #2
    \seq_put_right:NV \l__poly_lines_seq \l__poly_tmpa_seq
    \int_incr:N \l__poly_cstage_int

    \bool_if:nT {\l__poly_stage_bool || \int_compare_p:n
      {\l__poly_stage_int > \l__poly_cstage_int}}
    {
      \poly_sub:NNN \l__poly_tmpb_seq \l__poly_remainder_seq \l__poly_tmpa_seq
      \seq_set_eq:NN \l__poly_remainder_seq \l__poly_tmpb_seq
      \poly_trim:N \l__poly_remainder_seq
      \seq_put_right:NV \l__poly_lines_seq \l__poly_remainder_seq
      \int_incr:N \l__poly_cstage_int
    }
  }

  \int_set:Nn \l__poly_pad_int {\seq_count:N #1 + \seq_count:N
    #2-1}
  \tl_set:Nn \l__poly_sep_tl {&}
  \tl_set:Nn \l__poly_longdiv_sep_tl {\cr}
  \bool_set_true:N \l__poly_zeros_bool
  \int_set:Nn \l__poly_tmpa_int {2*\seq_count:N #1+1}
  \tl_set:Nx \l__poly_oline_tl {\exp_not:N\multispan {\int_use:N \l__poly_tmpa_int}\exp_not:N\hrulefill\exp_not:N\cr}
  \tl_set:Nx \l__poly_uline_tl {\exp_not:N\multispan {\int_eval:n {2*\seq_count:N #2 -1}}\exp_not:N\hrulefill\exp_not:N\cr}
  \tl_set:Nx \l__poly_neguline_tl {\exp_not:N\multispan {\int_eval:n {2*\seq_count:N #2}}\exp_not:N\hrulefill\exp_not:N\cr}
  \int_set:Nn \l__poly_trailing_int {\seq_count:N #2}
  \leavevmode\vbox{\halign {  $##$&&$\>##$ \crcr
    &
    \bool_if:NTF \l__poly_stage_bool
    {
      \bool_set_false:N \l__poly_trailing_bool
    }
    {
      \bool_set_true:N \l__poly_trailing_bool
      \int_set:Nn \l__poly_trailing_int {\l__poly_stage_int/2}
    }
    \poly_print:N \l__poly_quotient_seq
    \tl_use:N \l__poly_longdiv_sep_tl
    \noalign{\vskip-\normalbaselineskip\vskip\jot}
    \prg_replicate:nn {2*\seq_count:N #2} {&}
    \tl_use:N \l__poly_oline_tl
    \int_set:Nn \l__poly_pad_int {0}
    \bool_set_true:N \l__poly_trailing_bool
    \poly_print:N #2
    &
    \smash{\!\Bigr)}
    &
    \int_set:Nn \l__poly_pad_int {0}
    \bool_set_false:N \l__poly_trailing_bool
    \poly_print:N #1
    \tl_use:N \l__poly_longdiv_sep_tl
    \int_gzero:N \l__poly_tmpb_int
    \seq_map_inline:Nn \l__poly_lines_seq {
      \tl_gset:Nn \l__poly_tmpa_seq {##1}
      \int_gincr:N \l__poly_tmpb_int
      &
      \bool_set_true:N \l__poly_trailing_bool
      \poly_print:N \l__poly_tmpa_seq
      \bool_if:nT {\int_compare_p:n
        {\int_mod:nn{\l__poly_tmpb_int}{2} == 1} &&
        \int_compare_p:n {
          \l__poly_tmpb_int < 2*(\seq_count:N #1 - \seq_count:N #2)
        }
        &&
        \int_compare_p:n {
          \l__poly_tmpb_int != \seq_count:N \l__poly_lines_seq
        }
      } {
        &&\hfill\downarrow\hfill
      }
      \tl_use:N \l__poly_longdiv_sep_tl
      \int_compare:nT {\int_mod:nn{\l__poly_tmpb_int}{2} == 1} {
        \noalign{\vskip-\normalbaselineskip\vskip\jot}
        \int_compare:nNnTF { \seq_item:Nn \l__poly_tmpa_seq 1 } < 0
          {
            \prg_replicate:nn {2*\seq_count:N #2 + \l__poly_tmpb_int } {&}
            \tl_use:N \l__poly_neguline_tl
          }
          {
            \prg_replicate:nn {2*\seq_count:N #2 + \l__poly_tmpb_int + 1} {&}
            \tl_use:N \l__poly_uline_tl
          }
      }
    }
    \cr
  }}
  \group_end:
}
\cs_generate_variant:Nn \poly_longdiv:NN {cc}
\NewDocumentCommand \PolyPrint { O{} m } {
  \group_begin:
  \keys_set:nn { polynomial }
  {
    #1
  }
  \poly_print:c {polynomial #2}
  \group_end:
}
\NewDocumentCommand \PolySet { m m } {
  \seq_set_from_clist:cn {polynomial #1} {#2}
}
\NewDocumentCommand \PolyLongDiv {O{} m m } {
  \group_begin:
  \keys_set:nn { polynomial }
  {
    #1
  }
  \poly_longdiv:cc {polynomial #2} {polynomial #3}
  \group_end:
}
\ExplSyntaxOff

\begin{document}

\PolySet{a}{1,-12,0,-42}
\PolySet{b}{1,-3}
\(\PolyLongDiv{a}{b}\)

\PolySet{a}{1,-4,6,-4}
\PolySet{b}{1,-2}
\(\PolyLongDiv{a}{b}\)

\end{document}

这个实现比较简易,想要完全兼容 caption 宏包不是那么容易,你可以试试新的 wrapfig2 宏包,它兼容 wrapfig 宏包的接口,并且兼容 caption 宏包,也提供了的一些新的东西。

先给出修改后的代码:

\makeatletter
\def\@subtitle{}
%% 下面两行一般是不用的
%\def\@title{}
%\newcommand*{\title}[1]{\gdef\@title{#1}} %定义主标题变量
\newcommand*{\subtitle}[1]{\gdef\@subtitle{\relax #1}} %定义副标题变量
\NewDocumentCommand{\PrintTitle}{mg}
  {%
    \IfNoValueTF {#2}
    {#1}%
    {#1 \\ \flushright ——#2}%
  }
\newcommand{\TITLE}
  {%
    \ifx\@subtitle\@empty
      \PrintTitle{\@title}\relax
    \else
      \PrintTitle{\@title}{\@subtitle}%
    \fi
  }
\makeatother

使用时

\title{主标题}
\flushleft \zihao{-2} \heiti 题\quad 目:\TITLE \\

image.png

或,

\title{主标题}
\subtitle{副标题}
\flushleft \zihao{-2} \heiti 题\quad 目:\TITLE \\

image.png

\title\subtitle 的作用是存储其参数到 \@title\@subtitle 中,\ifx\@subtitle\@empty 是检测 subtitle 是否为空。

TeX 不使用“重载”这一概念,甚至没有“函数”这一概念,TeX 是一门宏语言,与其它编程语言的工作方式并不相同。

完整示例:

\documentclass{ctexart}
%\usepackage{xparse}

\makeatletter
\def\@subtitle{}
%\newcommand\@title{}
%\newcommand*{\title}[1]{\gdef\@title{#1}} %定义主标题变量
\newcommand*{\subtitle}[1]{\gdef\@subtitle{\relax #1}} %定义副标题变量
\NewDocumentCommand{\PrintTitle}{mg}
  {%
    \IfNoValueTF {#2}
    {#1}%
    {#1 \\ \flushright ——#2}%
  }
\newcommand{\TITLE}
  {%
    \ifx\@subtitle\@empty
      \PrintTitle{\@title}\relax
    \else
      \PrintTitle{\@title}{\@subtitle}%
    \fi
  }
\makeatother

\begin{document}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%输出文本
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\title{主标题}
\subtitle{副标题}
\flushleft \zihao{-2} \heiti 题\quad 目:\TITLE \\

\end{document}

设置 \ctexset{chapter/fixskip=false}

目录名称可以通过 \ctexset{contentsname={...}} 修改,或者重定义 \contentsname,一般不必直接修改 \tableofcontents 命令。

另外,你给的这个问题的代码是不能直接编译的,文档类、\usepackage 部分没有给,最重要的是 \abs@chapter 的定义没有给。

  1. \fancypagestyle 只是定义样式,需要使用 \pagestyle 应用样式,\thispagestyle 只是在当前页面应用样式;
  2. 你可能根本就没编译成功,这行代码
\renewcommand\contentsname{\textbf{目\quad录}}

xeCJKluatex-ja 下一般是无法编译的,应该写成

\renewcommand\contentsname{\textbf{目\quad 录}}

空格是必不可少的。
这是因为在 xeCJKluatex-ja 下,中文字符的类别码被设置为了 letter。

另外,使用了 ctexart 文档类就不必再使用 \usepackage{ctex} 了,UTF8 在 2.5 版(2020 年 5 月起)成为默认选项,一般也不必显示指定。

\documentclass[a4paper,12pt]{ctexart}
\usepackage{fancyhdr}
\usepackage{zhlipsum}
%--目录页眉页脚
\fancypagestyle{mulu}
  {
    \fancyhf{}
    \fancyhead[c]{**硕士学位论文\quad 目录} 
    \fancyfoot[c]{\thepage}
    \renewcommand{\headrulewidth}{1.5pt}
    \renewcommand{\footrulewidth}{1.5pt}
  }
%-目录页眉页脚
\begin{document}

%-----目录部分
\clearpage
\pagestyle{mulu}%--调用上面定义的\fancypagestyle{mulu}
\renewcommand\contentsname{\textbf{目\quad 录}}
    \addcontentsline{toc}{section}{目录}
    \begin{center}
    \tableofcontents%增加章节目录...
\end{center}

\clearpage
\pagestyle{headings}

\section{sec 1}
\zhlipsum[1-3]
\section{sec 2}
\zhlipsum[4-7]
\end{document} 

image.png

使用 hyperref 宏包提供的 \texorpdfstring 命令:

\section{\texorpdfstring{$\varphi$}{φ}}

请提供 MWE(最小工作示例)。一般情况都是能正常编译的。

这完全是字体的问题,如果使用 unicode-math,换一个数学字体就行了,基本上都是 45° 的:
image.png
可以使用 texdoc unimath-symbols 打开查看。

不使用 unicode-math,有些宏包提供 45° 的:
image.png
使用 texdoc symbols-a4 查看。

执行完 \item 时仍然是垂直模式,在这种情况下需要手动离开垂直模式,使用 \leavevmode\mode_leave_vertical: 均可。

在每个 \item 后紧跟 \mode_leave_vertical:
image.png

\documentclass{article}
\usepackage{varwidth}
\usepackage{graphicx}
\usepackage{lipsum}


\begin{document}
\ExplSyntaxOn
\coffin_new:N \l_test_a_coffin
\coffin_new:N \l_test_b_coffin
\hcoffin_set:Nn \l_test_b_coffin
  {
    \begin{varwidth}{\hsize}
      \lipsum[1]
      \begin{itemize}
        \item what~I~want
      \end{itemize}
    \end{varwidth}
  }
\hcoffin_set:Nn \l_tmpa_coffin
  {
    \begin{varwidth}{\hsize}
      \includegraphics[width = 2cm]{example-image-a}
    \end{varwidth}
  }
\coffin_join:NnnNnnnn
  \l_test_b_coffin { b } { r }
  \l_tmpa_coffin { t } { r }
  { 0pt } { 0pt }
\begin{enumerate}
  \item \mode_leave_vertical: % 加上这个
  \coffin_typeset:Nnnnn 
    \l_test_b_coffin { t } { l }
    { 0pt } { 0pt }
  \item \mode_leave_vertical: % 加上这个
  \hcoffin_set:Nn \l_test_a_coffin
    {
      \begin{varwidth}{\hsize}
        \lipsum[1]
        \begin{itemize}
          \item what~I~don't~want
        \end{itemize}
      \end{varwidth}
    }
  \hcoffin_set:Nn \l_tmpa_coffin
    {
      \begin{varwidth}{\hsize}
        \includegraphics[width = 2cm]{example-image-a}
      \end{varwidth}
    }
  \coffin_join:NnnNnnnn
    \l_test_a_coffin { b } { r }
    \l_tmpa_coffin { t } { r }
    { 0pt } { 0pt }
  \coffin_typeset:Nnnnn 
    \l_test_a_coffin { t } { l }
    { 0pt } { 0pt }
\end{enumerate}
\ExplSyntaxOff
\end{document}

另外再多说一句,由于 coffin 仍然是一个盒子,这意味着它不可断页。

解决办法有很多,如

  1. fancyhdr 宏包,设置页眉;
  2. 在旧的 LaTeX 版本中可以使用 everyshi 宏包,将其置于背景中;
  3. 在较新的 LaTeX 发行版中(Released 2020-10-01 及其后),可以使用 shipout 钩子;
  4. 使用 TikZ 的 current page node;
  5. 甚至可以直接放置,不需其它操作。

这里给出第3个办法的实现:

% !TEX program=xelatex
\documentclass{ctexart}
\usepackage[a4paper,hmargin=2.4cm,vmargin=2cm]{geometry}
\usepackage{array,multirow}

\begin{document}

\AddToHookNext{shipout/background}{\put(2.4cm,-3cm){%
  \makebox[\textwidth]{\heiti 编号:\hfill
    \begin{tabular}[c]{|c|c|c|}\hline
      \multirow{2}{1em}{类\\ 别} & 全日制教育硕士 & \hphantom{H} \\ \cline{2-3}
       & 非全日制教育硕士 & \\ \hline
    \end{tabular}}
}}

\thispagestyle{empty}

\leavevmode
\vfill

{\centering\zihao{2}\heiti 学位论文\par}

\vspace{1cm}

{\heiti 题目:}

\vspace{1cm}

\begin{center}
{\heiti
\renewcommand\arraystretch{1.5}%
\newcommand*\fixedbox[2][3cm]{%
  \begingroup
    \def\CJKglue{\hskip 0pt plus 2filll minus 1filll}%
    \makebox[#1][l]{#2}%
  \endgroup}
\newcommand*\infobox{\kern-5cm\makebox[5cm]}
\begin{tabular}{c@{:}>{\rule[-2pt]{5cm}{.4pt}}c}
\fixedbox{专业教学部} & \\
\fixedbox{专业名称}   & \infobox{教育学} \\
\fixedbox{指导教师}   & \\
\fixedbox{研究生}     & \\
\fixedbox{提交时间}   & \\
\end{tabular}}
\end{center}

\vspace{2cm}

{\centering\heiti 研究生院\quad 制\par}

\vspace{1cm}

\end{document}

image.png

\the<section> 后加一个 * 即可。

具体的,类似于:

\expandafter\def\expandafter\thesection\expandafter{\thesection*}

这里使用 \expandafter 是为了展开 \thesection 一次。
当然使用

\let\old@thesection\thesection
\def\thesection{\old@thesection*}

也可以。不过在使用之后必须立刻恢复 \thesection 的定义。

按照这个思路,可以写一个通用的宏 \starthis

\NewDocumentCommand \starthis { s m s o +m }
  {
    \group_begin:
    \exp_args:Nnf \cs_set:cpn { the \cs_to_str:N #2 } 
      { 
        \exp_after:wN \exp_after:wN \exp_after:wN 
        \exp_stop_f: \cs:w the \cs_to_str:N #2 \cs_end: * 
      }
    \IfBooleanT {#1}
      {
        \exp_args:Nnf \cs_set:cpn { CTEXthe \cs_to_str:N #2 } 
          { 
            \exp_after:wN \exp_after:wN \exp_after:wN 
            \exp_stop_f: \cs:w CTEXthe \cs_to_str:N #2 \cs_end: * 
          }
      }
    \IfBooleanTF {#3}
      { \IfValueTF {#4} { #2 * [#4] } { #2 * } }
      { \IfValueTF {#4} { #2   [#4] } { #2   } }
      {#5}
    \group_end:
  }
\ExplSyntaxOff

使用时只需

\starthis\chapter{章}

\starthis*\chapter{章}

\starthis\chapter[张]{章}

\starthis\section{节}

\starthis\subsection{小节}

* 的还会重定义 \CTEXthe<section>,以使得 \CTEXthe<section> 也有效。
对于完整的 \starthis\<section>*[...]{...} 也是支持的。

完整示例:

\documentclass{ctexart}
\usepackage{zhlipsum}
\usepackage[colorlinks]{hyperref}
\ExplSyntaxOn
\NewDocumentCommand \starthis { s m s o +m }
  {
    \group_begin:
    \exp_args:Nnf \cs_set:cpn { the \cs_to_str:N #2 } 
      { 
        \exp_after:wN \exp_after:wN \exp_after:wN 
        \exp_stop_f: \cs:w the \cs_to_str:N #2 \cs_end: \,* 
      }
    \IfBooleanT {#1}
      {
        \exp_args:Nnf \cs_set:cpn { CTEXthe \cs_to_str:N #2 } 
          { 
            \exp_after:wN \exp_after:wN \exp_after:wN 
            \exp_stop_f: \cs:w CTEXthe \cs_to_str:N #2 \cs_end: \,* 
          }
      }
    \IfBooleanTF {#3}
      { \IfValueTF {#4} { #2 * [#4] } { #2 * } }
      { \IfValueTF {#4} { #2   [#4] } { #2   } }
      {#5}
    \group_end:
  }
\ExplSyntaxOff

\begin{document}

\tableofcontents

\section{章一}

\begingroup
\expandafter\def\expandafter\thesubsection\expandafter{\thesubsection\,*}
\subsection{章一一}
\endgroup

\zhlipsum[1-2][name=zhufu]

\subsection{章一二}

\zhlipsum[4-6][name=zhufu]

\starthis\subsection{章一三}

\zhlipsum[7-9][name=zhufu]


\starthis\section{章二}

\subsection{章二一}

\zhlipsum[1-3][name=nanshanjing]

\starthis\subsection[章两两]{章二二}


\zhlipsum[4-7][name=nanshanjing]

\end{document}

image.png
image.png

有一个 tableof 宏包,不知道是不是你想要的。效果如下:
image.png

多 tag 也是支持的。

如果只是要在标题旁边标记tag,那应该由 titlesecctexheading 宏包来做。

附上代码:

\documentclass{article}
\usepackage{tableof}
\usepackage{lipsum}

\begin{document}

\tableofcontents

\section*{Tagged with `\texttt{sec1}'}
\tableof{sec1}

\section*{Tagged with `\texttt{subsec1}'}
\tableof{subsec1}

\section*{Tagged with `\texttt{subsec2}'}
\tableof{subsec2}


\toftagstart{sec1}

\section{lipsum 1}

\toftagthis{subsec1}
\subsection{lipsum 1.1}

\lipsum[1]

\toftagthis{subsec2}
\subsection{lipsum 1.2}

\lipsum[1]

\toftagstop{sec1}


\toftagstart{sec2}

\section{lipsum 2}

\toftagthis{subsec1}
\subsection{lipsum 2.1}

\lipsum[2]

\toftagthis{subsec2}
\subsection{lipsum 2.2}

\lipsum[2]

\toftagstop{sec2}


\toftagstart{sec3}

\section{lipsum 3}

\toftagthis{subsec1}
\subsection{lipsum 3.1}

\lipsum[3]

\toftagthis{subsec2}
\subsection{lipsum 3.2}

\lipsum[3]

\toftagstop{sec3}


\toftagstart{sec4}

\section{lipsum 4}

\toftagthis{subsec1}
\subsection{lipsum 4.1}

\lipsum[4]

\toftagthis{subsec2}
\subsection{lipsum 4.2}

\lipsum[4]

\toftagstop{sec4}

\end{document}

\documentclass{standalone}

\usepackage{forest}

\begin{document}

\forestset{
  declare dimen register=itemize folder indent,
  itemize folder indent=.6em,
  itemize rect/.style={tikz+={\fill ([xshift=-.9em,yshift=-2pt].child anchor) circle(1pt);}},
  itemize folder/.style={
    parent anchor=-children last,
    anchor=parent first,
    calign=child,
    calign primary child=1,
    for descendants={itemize rect},
    for children={
      child anchor=parent,
      anchor=parent first,
      edge={rotate/.option=!parent.grow},
      edge path={
        \noexpand\path[\forestoption{edge}]([xshift=\forestregister{itemize folder indent}]!u.parent anchor) |- ([yshift=-2pt].child anchor)\forestoption{edge label};
      },
    },
    after packing node={
      if n children=0{}{
        tempdiml=l_sep()-l("!1"),
        tempdims={-abs(max_s("","")-min_s("",""))-s_sep()},
        for children={
          l+=tempdiml,
          s+=tempdims()*(reversed()-0.5)*2,
        },
      },
    },
  }
}

\begin{forest}
    for root={itemize folder indent=.8em},
    for tree={grow'=0,itemize folder,font=\ttfamily,inner ysep=0pt,l sep=1.7em}
    [Baby Linear Functional analysis
      [normed space
        [$L^p$ space]
        [Banach fixed point theorem]
        [Hahn-Banach theorem
          [separation of convex sets]
          [weak convergence/dual operator,inner ysep=-2.5pt]
          [Banach-Mazur theorem]
          [Banach-Alaoglu-Bourbaki Theorem]
        ]
        [Baire Category theorem
          [Uniform boundedness principle]
          [Open mapping theorem]
          [Closed graph theorem]
        ]
      ]
      [Hilbert space
        [projections]
        [Riesz representation]
        [Fourier series]
        [Lax-Milgram theorem]
        [Self adjoint operators
          [Eigenvalue problem]
          [Spectral theorem]
        ]
      ]
    ]
\end{forest}

\end{document}

间距自己调吧。
image.png

在 xelatex 下,xeCJK 宏包有一个 CheckSingle 选项用以控制是否检查段末的孤字。

\documentclass[zihao=-4]{ctexart}
% 480bp = 40*12bp % 每行40字
\usepackage[textwidth=480bp]{geometry}
\begin{document}

\noindent
一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十

\medskip

一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九。%十

\xeCJKsetup{CheckSingle=true}

一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九十一二三四五六七八九。%十

\end{document}

image.png

可以看到使用 CheckSingle 的不同之处。“只有在段末的最后一个字是 CJK 文字或者标点符号,并且倒数第二和第三个字都是文字才能正确处理”。

对于单句在一个页面,可以使用 \enlargethispage{<dim>} 暂时扩大该页的高度。如

文字
\enlargethispage{12bp}

发布
问题