如何更改图表列表和表格列表中图表编号的格式?

如何更改图表列表和表格列表中图表编号的格式?

我使用

\listoftables

命令,但它在列表中使用的默认编号不是我想要的。它现在的样子是这样的:

在此处输入图片描述

但是,我希望将“1.1”、“1.2”等数字改为小写罗马数字。我不知道该怎么做。我的代码如下:

\documentclass[12pt,english, openany]{book}

\usepackage[]{graphicx}
\usepackage[]{color}
\usepackage{alltt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathptmx}
\usepackage{tocloft}



\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{12pt}

% Set page margins
\usepackage[top=60pt,bottom=60pt,left=78pt,right=78pt]{geometry}
\usepackage{subcaption}
% Package used for placeholder text
\usepackage{lipsum}
\usepackage{booktabs}
\usepackage{multirow}
% Prevents LaTeX from filling out a page to the bottom
\raggedbottom

\usepackage[spanish, es-tabla]{babel}

% All page numbers positioned at the bottom of the page
\usepackage{fancyhdr}
\fancyhf{} % clear all header and footers
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt} % remove the header rule
\pagestyle{fancy}

% Changes the style of chapter headings
\usepackage{titlesec}
\titleformat{\chapter}
   {\normalfont\LARGE\bfseries}{\thechapter.}{1em}{}
% Change distance between chapter header and text
\titlespacing{\chapter}{0pt}{40pt}{2\baselineskip}

% Adds table captions above the table per default
\usepackage{float}
\floatstyle{plaintop}
\restylefloat{table}
% Adds space between caption and table
\usepackage[tableposition=top]{caption}

% add cc license
\usepackage[
type={CC},
modifier={by-nc-sa},
version={4.0},
]{doclicense}

% Adds hyperlinks to references and ToC
\usepackage{hyperref}
% Uncomment the line below this block to set all hyperlink color to black
\hypersetup{
    colorlinks,
    linkcolor={blue},
    citecolor={green!90!black},
    urlcolor={red!70!black}
}
%\hypersetup{hidelinks,linkcolor = black} % Changes the link color to black and hides the hideous red border that usually is created

% Set specific color for hyperref
\usepackage{xcolor}


% tcolorbox; Notice! add "-shell-escape" to the compile command
\usepackage{tcolorbox}

% If multiple images are to be added, a folder (path) with all the images can be added here 
\graphicspath{ {Figures/} }

\begin{document}

% Separates the first part of the report/thesis in Roman numerals:
\frontmatter

{\hypersetup{linkcolor=black}
 % or \hypersetup{linkcolor=black}, if the colorlinks=true option of hyperref is used
 \tableofcontents
 \listoftables
 \listoffigures
}

\mainmatter
\stepcounter{chapter} % in lieu of a \chapter directive
\begin{table}[h!]\caption{Ejemplo de tabla}\end{table}
\begin{table}[h!]\caption{Ejemplo de tabla 2}\end{table}
\end{document}

任何帮助都将不胜感激!

答案1

以下解决方案将化合物figuretable数字从1.11.2等更改为1.i1.ii等——但仅限于图片列表和表格列表中。我理解这是 OP 的格式化目标。

下面的代码必须用 LuaLaTeX 编译。它的工作原理是设置一个 Lua 函数,该函数扫描\frontmatter文档部分的内容(特别是 .lot 和 .lof 文件),并替换以下形式的行

\contentsline {table}{\numberline {1.1}{...

即时

\contentsline {table}{\numberline {1.\es@scroman {i}}{...

由于\listoftables\listoffigures指令只应出现在\frontmatter文档的部分中,因此主 Lua 函数在环境开始时被激活,并在遇到指令document时停用。我所说的“激活”是指它被分配给 LuaTeX 的\mainmatterprocess_input_buffer回调,让该函数充当输入流上的预处理器TeX 开始其常规处理程序。

使用该\es@scroman宏是因为 OP 使用babel选项spanish和来加载包es-tabla

在此处输入图片描述

在下面的代码中,新内容放在顶部。序言的其余部分与 OP 的版本接近。

% !TEX TS-program = lualatex
\documentclass[12pt,english,openany]{book}

\usepackage{luacode} % for 'luacode*' environment
\begin{luacode*}
-- Define an auxiliary Lua function:
function to_roman ( u,v ) 
  -- "\es@scroman" is defined by babel's "spanish" option
  v = v:gsub ( "(%d+%.)(%d+)" , "%1\\es@scroman {\\romannumeral %2}" )
  return u..v
end
-- Define the main Lua function:
function roman_nums_lot_lof ( s ) 
  if s:find ( "\\mainmatter" ) then -- de-activate the Lua function:
    luatexbase.remove_from_callback ( "process_input_buffer" , "roman_nums_lot_lof")
  else -- keep sweeping over input lines
    s = s:gsub ( "({table}{\\numberline )(%b{})", to_roman )
    s = s:gsub ( "({figure}{\\numberline )(%b{})", to_roman )
  end
  return s
end
\end{luacode*}

% Activate the main Lua function at the start of the 'document' environment:
\AtBeginDocument{\directlua{luatexbase.add_to_callback ( 
  "process_input_buffer" , roman_nums_lot_lof , "roman_nums_lot_lof")}}
 

\usepackage{tocloft} 
% Change indentation amounts as needed:
\cftsetindents{table}{0em}{3.75em}  % accomodates '18' roman numeral
\cftsetindents{figure}{0em}{8.75em} % accommodates '1888' roman numeral



%%%%%%%%%% Remainder of preamble is close to OP's version 
%%%%%%%%%% (with some streamlining applied)

\usepackage{graphicx}
% If multiple images are to be added, a folder (path) with 
% all the images can be added here:
\graphicspath{ {Figures/} }

\usepackage{xcolor}

\usepackage{alltt}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{mathptmx} 
%% Do consider loading 'newtxtext' and 'newtxmath' instead of 'mathptmx'

\setcounter{secnumdepth}{3}
\setcounter{tocdepth}{3}
\setlength{\parskip}{\smallskipamount}
\setlength{\parindent}{12pt}

% Set text block margins:
\usepackage[vmargin=60pt,hmargin=78pt]{geometry}

\usepackage{lipsum} % for placeholder/filler text
\usepackage{booktabs}
\usepackage{multirow}

% Prevent LaTeX from filling out a page to the bottom:
\raggedbottom

\usepackage[spanish, es-tabla]{babel}

% All page numbers placed at bottom of the page:
\usepackage{fancyhdr}
\fancyhf{} % clear all header and footers
\fancyfoot[C]{\thepage}
\renewcommand{\headrulewidth}{0pt} % remove the header rule
\pagestyle{fancy}

% Changes style of chapter headings
\usepackage{titlesec}
\titleformat{\chapter}{\normalfont\LARGE\bfseries}{\thechapter.}{1em}{}
% Change distance between chapter header and text
\titlespacing{\chapter}{0pt}{40pt}{2\baselineskip}

% Adds table captions above the table per default
\usepackage{float}
\floatstyle{plaintop}
\restylefloat{table}

% Add space between caption and table
\usepackage[tableposition=top]{caption}
\usepackage{subcaption}

% Add cc license
\usepackage[type={CC},modifier={by-nc-sa},version={4.0}]{doclicense}

\usepackage{tcolorbox}

% Add hyperlinks to cross-references and ToC
\usepackage{hyperref}
\hypersetup{
    colorlinks,
    linkcolor={blue},
    citecolor={green!90!black},
    urlcolor ={red!70!black}
}
% Uncomment next line to set all hyperlink colors to black:
% \hypersetup{colorlinks,allcolors = black}

    
\begin{document}

% Use roman numerals for page numbers in "frontmatter"
\frontmatter
\begingroup
\hypersetup{linkcolor=black}
\tableofcontents
\listoftables
\listoffigures
\endgroup


\mainmatter % Reset 'page' counter & switch to arabic numerals for page numbers

\chapter{Primer capitulo}

% Create some dummy instances of 'table' and 'figure' environments:       
\begin{table}[h!]\caption{Ejemplo de tabla}\end{table}
\setcounter{table}{17}
\begin{table}[h!]\caption{Ejemplo de tabla \arabic{table}}\end{table}   
\begin{figure}[h!]\caption{Ejemplo de figura}\end{figure}
\setcounter{figure}{1887} % clearly going crazy...
\begin{figure}[h!]\caption{Ejemplo de figura \arabic{figure}}\end{figure}

\end{document}

相关内容