关闭标题前缀而不使用标题包

关闭标题前缀而不使用标题包

如何在不使用包的情况下从图形、表格等中删除标题前缀(即图 1:、表 1:)caption?我不想这样做的原因是因为我正在使用tufte-latex已经重新定义\caption命令的命令,所以它不起作用。

编辑:更具体地说,如果我选择使用常规\caption命令,则图形会编号并显示在图形列表中。如果我使用替代方法,则图形不会编号,也不会显示在图形列表中。表格也是如此。

提前致谢!

答案1

tufte-common.def为了适应\varcaption具有语法的命令,进行了一些修改

\varcaption[<offset>]{<caption text>}

(可选参数与的第二个可选参数类似\caption)。

\documentclass{tufte-book}
\usepackage{regexpatch}

\usepackage{lipsum} % just for the example

\makeatletter
\newcommand{\varcaption}[2][0pt]{%
  \gsetlength{\@tufte@caption@vertical@offset}{-#1}%
  \gdef\@tufte@stored@varcaption{#2}%
}
\xpatchcmd{\end@tufte@float}
  {\par\vspace}
  {\ifthenelse{\NOT\equal{\@tufte@stored@varcaption}{}}{\@tufte@varcaption{\@tufte@stored@varcaption}}{}\par\vspace}
  {}{}
\xapptocmd{\end@tufte@float}{\gdef\@tufte@stored@varcaption{}}{}{}
\gdef\@tufte@stored@varcaption{} % initialize
\newcommand\@tufte@varcaption[1]{%
  \begingroup
  \@parboxrestore 
  \if@minipage\@setminipage\fi
  \@tufte@caption@font
  \@tufte@caption@justification
  \noindent #1\par
  \endgroup
}
\makeatother

\begin{document}

\listoffigures

\chapter{Title}

\lipsum[2]

\begin{figure}
Something
\caption{A numbered caption}
\end{figure}

\lipsum[3]

\begin{figure}
Something
\varcaption{An unnumbered caption}
\end{figure}

\lipsum[4]

\end{document}

您会发现第二个标题未列在图表列表中。

在此处输入图片描述

regexpatch不带;复制文档序言中的所有内容(包括)\makeatletter的版本\makeatother

\documentclass{tufte-book}

\usepackage{lipsum} % just for the example

\makeatletter
\newcommand{\varcaption}[2][0pt]{%
  \gsetlength{\@tufte@caption@vertical@offset}{-#1}%
  \gdef\@tufte@stored@varcaption{#2}%
}
\gdef\@tufte@stored@varcaption{} % initialize
\newcommand\@tufte@varcaption[1]{%
  \begingroup
  \@parboxrestore 
  \if@minipage\@setminipage\fi
  \@tufte@caption@font
  \@tufte@caption@justification
  \noindent #1\par
  \endgroup
}
\def\end@tufte@float{%
      \par\hbox{}\vspace{-\baselineskip}\ifthenelse{\prevdepth>0}{\vspace{-\prevdepth}}{}% align baselines of boxes
      \end{minipage}%
    \end{lrbox}%
    % build the caption box
    \begin{lrbox}{\@tufte@caption@box}%
      \begin{minipage}[\floatalignment]{\marginparwidth}\hbox{}%
        \ifthenelse{\NOT\equal{\@tufte@stored@caption}{}}{\@tufte@orig@caption[\@tufte@stored@shortcaption]{\@tufte@stored@caption}}{}%
        \ifthenelse{\NOT\equal{\@tufte@stored@label}{}}{\@tufte@orig@label{\@tufte@stored@label}}{}%
        \ifthenelse{\NOT\equal{\@tufte@stored@varcaption}{}}{\@tufte@varcaption{\@tufte@stored@varcaption}}{}
        \par\vspace{-\prevdepth}%% TODO: DOUBLE-CHECK FOR SAFETY
      \end{minipage}%
    \end{lrbox}%
    % now typeset the stored boxes
    \begin{fullwidth}%
      \begin{minipage}[\floatalignment]{\linewidth}%
        \ifthenelse{\boolean{@tufte@float@star}}%
          {\@tufte@float@fullwidth[\@tufte@caption@vertical@offset]{\@tufte@figure@box}{\@tufte@caption@box}}%
          {\@tufte@float@textwidth[\@tufte@caption@vertical@offset]{\@tufte@figure@box}{\@tufte@caption@box}}%
      \end{minipage}%
    \end{fullwidth}%
    \@tufte@orig@endfloat% end original LaTeX float environment
    % output debug info
    \ifthenelse{\boolean{@tufte@debug}}{%
      \typeout{^^J^^J----------- Tufte-LaTeX float information ----------}%
      \ifthenelse{\equal{\@tufte@stored@label}{}}%
        {\typeout{Warning: Float unlabeled!}}%
        {\typeout{Float label: [\@tufte@stored@label]}}%
      \typeout{Page number: [\thepage]}%
      \def\MessageBreak{^^J}%
      \typeout{\@tufte@float@debug@info}%
      \ifthenelse{\boolean{@tufte@symmetric}}%
        {\typeout{Symmetric: [true]}}%
        {\typeout{Symmetric: [false]}}%
      \typeout{----------------------------------------------------^^J^^J}%
    }{}%
    % reset commands and temp boxes and captions
    \gdef\@tufte@float@debug@info{}%
    \let\caption\@tufte@orig@caption%
    \let\label\@tufte@orig@label%
    \begin{lrbox}{\@tufte@figure@box}\hbox{}\end{lrbox}%
    \begin{lrbox}{\@tufte@caption@box}\hbox{}\end{lrbox}%
    \gdef\@tufte@stored@shortcaption{}%
    \gdef\@tufte@stored@caption{}%
    \gdef\@tufte@stored@label{}%
    \gsetlength{\@tufte@caption@vertical@offset}{0pt}% reset caption offset
    \gdef\@tufte@stored@varcaption{}
  }
\makeatother

\begin{document}

\listoffigures

\chapter{Title}

\lipsum[2]

\begin{figure}
Something
\caption{A numbered caption}
\end{figure}

\lipsum[3]

\begin{figure}
Something
\varcaption{An unnumbered caption}
\end{figure}

\lipsum[4]

\end{document}

支持marginfiguremargintable

使用以下必须添加到最后一个代码之前的代 码,您也可以在和中\makeatother使用。\varcaptionmarginfiguremargintable

\renewenvironment{@tufte@margin@float}[2][-1.2ex]%
  {\FloatBarrier% process all floats before this point so the figure/table numbers stay in order.
  \begin{lrbox}{\@tufte@margin@floatbox}%
  \begin{minipage}{\marginparwidth}%
    \renewcommand\varcaption[2][]{\par\@tufte@varcaption{##2}}%
    \@tufte@caption@font%
    \def\@captype{#2}%
    \hbox{}\vspace*{#1}%
    \@tufte@caption@justification%
    \@tufte@margin@par%
    \noindent%
  }
  {\end{minipage}%
  \end{lrbox}%
  \marginpar{\usebox{\@tufte@margin@floatbox}}%
  }

答案2

在评论中,我告诉 OP 如何在文本中添加不带编号的图形。这里,根据 OP 的后续评论,我展示了如何将未编号的图形放入边距,类似于类marginfigure的边距tufte-book

\documentclass{tufte-book}
\usepackage{lipsum,graphicx}
\begin{document}
\listoffigures

\noindent\hrulefill

\lipsum[1]
\marginpar{
\includegraphics[width=.5in]{example-image-A}\par
\footnotesize This is my caption
}
\lipsum[2]
\begin{marginfigure}
\includegraphics[width=.5in]{example-image-A}\par
\caption{margin figure}
\end{marginfigure}
\lipsum[3]
\end{document}

在此处输入图片描述

相关内容