30 captionof 后如何自定义 ref 时显示的名字

发布于 2023-04-15 16:04:47

我插入了一张图片, 然后用 captionof 给了它编号, 然后在后面引用它, 搜了一下, 发现图片编号可以用阿拉伯数字, 罗马数字, 英文字母等, 但是有时候我需要叫它如图甲, 如图乙, 请问如何指定?

感谢回答

查看更多

关注者
0
被浏览
862
Kurfürst
Kurfürst 2023-04-15
这家伙很懒,什么也没写!

可以按元素序号访问凭据表

\documentclass{ctexart}
\usepackage{zhlipsum}
\usepackage{hyperref}
\ExplSyntaxOn
\tl_new:N \g_cn_ordnum_tl
\tl_gset:Nn \g_cn_ordnum_tl {甲乙丙丁戊己庚辛壬癸}
\cs_gset:Npn \doc_arabic_to_cn_ordnum_cs:n #1 {
    \tl_item:Nn \g_cn_ordnum_tl {#1}
}
\renewcommand{\figurename}{图\!\!}
\renewcommand{\thefigure}{\doc_arabic_to_cn_ordnum_cs:n {\arabic{figure}}}
\ExplSyntaxOff


\begin{document}
\emph{{\huge 请见图\ref{fig:example1}、\ref{fig:example2}和\ref{fig:example3}}}

\zhlipsum[1]    
\begin{figure}[htbp]
    \centering
    \fbox{\rule{0pt}{2in} \huge 第一张图片 \rule{2in}{0pt}}
    \caption{这是第一张图片的标题}
    \label{fig:example1}
\end{figure}
\emph{{\huge 图\ref{fig:example3}所示为第三张图片。}}

\zhlipsum[2]    
\begin{figure}[htbp]
    \centering
    \fbox{\rule{0pt}{2in} \huge 第二张图片\rule{2in}{0pt}}
    \caption{这是第二张图片的标题}
    \label{fig:example2}
\end{figure}
\zhlipsum[3]
\begin{figure}[htbp]
    \centering
    \fbox{\rule{0pt}{2in} \huge 第三张图片\rule{2in}{0pt}}
    \caption{这是第三张图片的标题}
    \label{fig:example3}
\end{figure}    
    \emph{{\huge 图\ref{fig:example1}所示为第一张图片。}}
    
\zhlipsum[4]    
\end{document}

甲乙丙丁戊己庚辛壬癸_页面_1.jpg
甲乙丙丁戊己庚辛壬癸_页面_2.jpg
甲乙丙丁戊己庚辛壬癸_页面_3.jpg

2 个回答
芒果不盲
芒果不盲 2023-04-15
学好TiKZ和tcolorbox!

你可以使用

\def\sab#1{%
\expandafter\ifcase\csname c@#1\endcsname%
  \or 甲%
  \or 乙%
  \or 丙%
  \or 丁%
  \or 戊%
  \or 己%
  \or 庚%
  \or 辛%
  \or 壬%
  \or 癸%
\fi%
}

定义一种计数器(\sab) Stems-and-Branches(天干地支), 然后修改 \thefigure

\def\thefigure{\sab{figure}}

源码如下:

\documentclass{ctexart}
\usepackage{caption}
% Stems-and-Branches

\def\sab#1{%
\expandafter\ifcase\csname c@#1\endcsname%
  \or 甲\or 乙\or 丙\or 丁\or 戊\or 己\or 庚\or 辛\or 壬\or 癸
\fi%
}
\def\thefigure{\sab{figure}}
\usepackage{graphicx}
\begin{document}
\begin{figure}
    \centering
    \includegraphics[width = 5cm]{example-image}
    \caption{this is a picture.}\label{fig:a}
\end{figure}
\begin{center}
    \includegraphics[width = 5cm]{example-image-a}
    \captionof{figure}{this is a fig.}\label{fig:b}
\end{center}

\verb|hahahhahahha and this is \ref{fig:a} and \ref{fig:b}| $==>$

hahahhahahha and this is \ref{fig:a} and \ref{fig:b}
\end{document}

image.png


  • 下次提问希望能够尽可能提供最小工作示例
  • 楼上用了 LaTeX3 我就用 TeX 吧(

撰写答案

请登录后再发布答案,点击登录

发布
问题

分享
好友

手机
浏览

扫码手机浏览