TransWikia.com

How do I change the format of figure and table numbers in the list of figures and list of tables?

TeX - LaTeX Asked by Juan Pablo Naranjo on April 5, 2021

I create a list of tables using the

listoftables

command, but the default numbering it uses in the list is not what I want. This is what it looks like right now:

enter image description here

However, I would like for the numbering that is "1.1", "1.2" to be changed to lower case roman numerals. I don’t know how to get around doing this. Here is how my code looks:

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}
   {normalfontLARGEbfseries}{thechapter.}{1em}{}
% Change distance between chapter header and text
titlespacing{chapter}{0pt}{40pt}{2baselineskip}

% 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}

Any help is appreciated!

One Answer

The following solution changes the compound figure and table numbers from 1.1, 1.2, etc to 1.i, 1.ii, etc. -- but only in the List of Figures and the List of Tables. I understand this to be the OP's formatting objective.

The code below must be compiled with LuaLaTeX. It works by setting up a Lua function that sweeps over the contents of the frontmatter portion of the document -- in particular, the .lot and .lof files -- and by replacing lines of the form

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

on the fly with

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

As the listoftables and listoffigures directives are only supposed to occur in the frontmatter portion of the document, the main Lua function is activated at the start of the document environment and is deactivated when the mainmatter instruction is encountered. By "activation" I mean that it gets assigned to LuaTeX's process_input_buffer callback, letting the function act like a pre-processor on the input stream before TeX starts its usual processing routines.

The es@scroman macro is used because the OP loads the babel package with the options spanish and es-tabla.

enter image description here

In the code below, new material is placed at the top. The remainder of the preamble is close to the OP's version.

% !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+)" , "%1es@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}{normalfontLARGEbfseries}{thechapter.}{1em}{}
% Change distance between chapter header and text
titlespacing{chapter}{0pt}{40pt}{2baselineskip}

% 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}

Answered by Mico on April 5, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP