21 Comments

  1. Fernando

    Hello! I hope you are all ok.

    I am doing a work where I am using a lot of tables and figures. In both cases besides the caption I need to provide the source of the data and also to give some explanation right above or below the figure/table. However, in the “List of figures” and “List of Tables” I only want the name of the figure/table that I introduce with caption. For example, if I want to put a figure about copper consumption where data is from Bloomberg:

    \caption{Copper Consumption. Source: Bloomberg}

    How can I do this avoiding to put the other coments (in this case “Source: Bloomberg”) inside {} so that they do not appear in the list of figures/tables and only above or below the figure/table which I refer?

    This blog is great it is a great help.

    Best regards!

    • tom

      Hi Fernando,

      The \caption command takes an optional argument, for the text to be produced in the list of figures/tables.

      Therefore, this is what you can do:

      \caption[Copper Consumption]{Copper Consumption. Source: Bloomberg}
  2. Polat

    how can I leave some space between figurenumber and name in this example which I have added a picture

    The link is:
    https://hizliresim.com/EqkOr8

    the coding of listoffigures in my ct file is below:

    \newcommand\listoffigures{%
        \if@twocolumn
          \@restonecoltrue\onecolumn
        \else
          \@restonecolfalse
        \fi
        \chapter{\listfigurename}%
          \@mkboth{\MakeUppercase\listfigurename}%
                  {\MakeUppercase\listfigurename}%
        \@starttoc{lof}%
        \if@restonecol\twocolumn\fi
        }
    \newcommand*\l@figure{\@dottedtocline{1}{1.5em}{2.3em}}

    Sorry I don’t know any coding for latex. I am only user not programmer of latex.
    What do I need to add and where in the code snippet. I am using \listoffigures command in my real document and it show figures automatically so I believe I need to change something here on the code I posted.

    I would be grateful if you can help

    Thanks

    • tom

      Hi Polat,

      I suggest to use the tocloft package to add extra space between the figure number and the caption. Hope this helps.

      Best Tom.

      Minimal working example:

      \documentclass{article}
      
      \usepackage{tocloft}
      \renewcommand\cftfignumwidth{1.8cm} % Adds extra space to figure number in LOF
      \renewcommand\cftfigpresnum{Figure }
      \renewcommand\cftfigaftersnum{:}
      
      \begin{document}
      \listoffigures
      \section{Introduction}
      \begin{figure}[ht]
      \centering
      \rule{0.3\linewidth}{0.3\linewidth}
      \caption{Some figure}
      \label{fig:myfig}
      \end{figure}
      \end{document}
  3. Fernando

    Hello Tom I hope you are doing fine.

    I was wondering if you can help me with an idea of how can I insert a text inside a box in my document. I tried using \usepackage[framemethod=TikZ]{mdframed} (I followed the tips from http://tex.stackexchange.com/questions/36524/how-to-put-a-framed-box-around-text-math-enviroment)

    However with this procedure the box breaks between pages.

    Do you have a better idea of doing this?

    Sorry my questions but I believe this is the best forum to get different latex insights.

    Best Regards.

    • tom

      Hi Fernando,

      Please provide a minimal working example in order for me to better understand what you are trying to do.

      In the meantime, you may find this site helpful: Boxes on LaTeX Wikibooks.

      Also, please try to find an article that is related to your question if possible, using the search field on the right.

      Best wishes, Tom

  4. Fernando

    Thank you very much Tom. Yes I was searching on different websites and one of them was wikibooks.

    I solved one part of my question. I made a box in my document that I placed inside a figure environment (to be able to place the box on top of the page).

    My only question is that if there is a way to reference the box as you can do it with figures and tables using \ref.

    Here is a minima example of my question (first is defined the box properties and then the box is created on the document):

    \usepackage[framemethod=TikZ]{mdframed}
    \mdfdefinestyle{MyFrame}{%
        nobreak,    
        linecolor=blue,
        outerlinewidth=0.5pt,
        roundcorner=20pt,
        innertopmargin=\baselineskip,
        innerbottommargin=\baselineskip,
        innerrightmargin=20pt,
        innerleftmargin=20pt,
        frametitlealignment=\center,
        backgroundcolor=gray!30!white}
        %backgroundcolor=lightgray}
    \usepackage{fancybox}
    
    ......document....
    
    \begin{figure}[t]
    \begin{mdframed}[%
    style=MyFrame,
    frametitle={Box 1.1: this is my box},
    ]
    bla bbla bla
    \end{mdframed}
    \end{figure}

    I would like to know if there is a simple way to reference the box (since I do not want to use the caption option for the figure as it would need to be referenced as a box).

    Thank you very much for all the help.

    Regards!

    • tom

      Hi Fernando,

      Here is a possible solution that you might change according to your needs. It creates a new environment mybox together with a counter. Currently, the counter prints the section followed by its number and is reset at every section. But that can be changed. The examples below show how to use and reference the environment. I also wrapped the environment in a minipage environment to place it on top of the page whenever possible.

      Hope this is what you were looking for.

      Best, Tom

      \documentclass{article}
      \usepackage[framemethod=TikZ]{mdframed}
      \mdfdefinestyle{MyFrame}{nobreak,linecolor=blue,outerlinewidth=0.5pt,
          roundcorner=20pt,innertopmargin=\baselineskip,innerbottommargin=\baselineskip,
          innerrightmargin=20pt,innerleftmargin=20pt,frametitlealignment=\center,
          backgroundcolor=gray!30!white}
      \newcounter{mybox}[section] \setcounter{mybox}{0}
      \renewcommand{\themybox}{\arabic{section}.\arabic{mybox}}
      \newenvironment{mybox}[2]{%
          \refstepcounter{mybox}%
          \mdfsetup{%
          style=MyFrame,
          frametitle={Box \themybox:\ #1\label{#2}}}%
      \begin{minipage}[t]{\linewidth}\begin{mdframed}[]\relax%
      }{\end{mdframed}\end{minipage}}
      
      \begin{document}
      \section{Some section}
      \begin{mybox}{this is my box}{bx:box1}
      bla bbla bla
      \end{mybox}
      This is a reference to my box \ref{bx:box1}
      
      \section{Some other section}
      \begin{mybox}{This is another box}{bx:box2}
      bla bbla bla
      \end{mybox}
      This is a reference to my box \ref{bx:box2}
      \end{document}
  5. Fernando

    Hello Tom that worked great! Now I am ok with that part that was giving me many problems.

    One more question if anyone is able to help me with this please.

    Now I am trying to align different boxes in one page where the boxes have different size (the text is different inside them). I am trying to use the boxes inside a figure environment so they can be aligned, but does not work properly. I would like to give you an idea but I can not attach a picture here of what I am trying to do.

    Anyway here is a minimal working example (each box consist of a list of elements for different countries and the countries are the titles of each box):

    …….

    \tcbset{width=(\linewidth),before=,after=\hfill,arc=0mm,
    colframe=blue!65!black,colback=black!10!white,fonttitle=\bfseries}
    
    \begin{figure}[H]
    \begin{subfigure}{0.3\linewidth}
    \begin{tcolorbox}[title = China]
    Alumina\\Bauxite\\Nickel\\.....\\Zinc
    \end{tcolorbox}
    \end{subfigure}
    \begin{subfigure}{0.3\linewidth}
    \begin{tcolorbox}[title = USA]
    Bent\\RREE\\Ber... \\Tellurium
    \end{tcolorbox}
    \end{subfigure}
    
    \begin{subfigure}{0.3\linewidth}
    \begin{tcolorbox}[title = South Africa]
    Chromium\\PGM\\...\\Graphite
    \end{tcolorbox}
    \end{subfigure}
    \end{figure}

    ….

    Thank you for all the incredible help.

    Best Regards!

    • tom

      Hi Fernando,

      Try the minipage environment instead of subfigure from the subcaption package. Below is a possible solution. Alternatively, you could just make all the boxes the same size by adding extra empty lines.

      Cheers, Tom.

      \documentclass[a4paper,12pt]{article}
      \usepackage{tcolorbox}
      \tcbset{width=(\linewidth),before=,after=\hfill,arc=0mm,
      colframe=blue!65!black,colback=black!10!white,fonttitle=\bfseries,sidebyside align=top}
      
      \begin{document}
          \begin{minipage}[t][10pt][t]{0.3\linewidth}\vspace{0pt}
              \begin{tcolorbox}[title = China, sidebyside align=top]
                  Alumina\\Bauxite\\Nickel\\…..\\Zinc
              \end{tcolorbox}
              \begin{tcolorbox}[title = South Africa]
                  Chromium\\PGM\\…\\Graphite
              \end{tcolorbox}
          \end{minipage}
          \begin{minipage}[t][10pt][t]{0.3\linewidth}\vspace{0pt}
              \begin{tcolorbox}[title = USA,sidebyside align=top]
                  Bent\\RREE\\Ber… \\Tellurium
              \end{tcolorbox}
          \end{minipage}
      \end{document} 
  6. Fernando

    Hi there. I am sorry if this question should not be added here but is similar to table of figures.
    I was wondering if someone knows how to “tell” LaTeX to print an Index of Boxes (“Recuadros” for me), in a similar way to the regular Index of Tables. In the last case there is an extra space between tables from different sections, something I have been unable to to in the case of boxes.
    The way I am doing the boxes is first to define the style and then the numbering for the boxes (using mdframed):

    \usepackage[framemethod=TikZ]{mdframed}
    \definecolor{palegoldenrod}{RGB}{238,232,170}
    \definecolor{midnightblue}{RGB}{25,25,112}
    \mdfdefinestyle{MyFrame}{%
        nobreak,    
        linecolor=midnightblue,
        outerlinewidth=0.5pt,
        roundcorner=20pt,
        innertopmargin=\baselineskip,
        innerbottommargin=\baselineskip,
        innerrightmargin=20pt,
        innerleftmargin=20pt,
        frametitlealignment=\center,
        backgroundcolor=palegoldenrod}
    \usepackage{tocloft}
    \usepackage{xpatch}
    
    \newcounter{infobox}[chapter]
    \newenvironment{infobox}[1][]{%
      \refstepcounter{infobox}%
      \begin{mdframed}[%
        style=MyFrame,
        frametitle={Recuadro \theinfobox\ #1},
        ]%
        \addcontentsline{lob}{section}{\protect\numberline{\theinfobox~}#1}%
      }{%
      \end{mdframed}
    }
    
    \makeatletter
    \xpatchcmd{\@chapter}{%
      \chaptermark{#1}%
    }{
      \chaptermark{#1}%
      \addtocontents{lob}{\protect\addvspace{10\p@}}%
    }{\typeout{success}}{}
    
    %
    \newcommand\listboxname{\LARGE\'INDICE DE RECUADROS}
    \newcommand\listofboxes{%
      \chapter*{\protect\listboxname}
      \@starttoc{lob}
    }
    \renewcommand{\theinfobox}{\thechapter.\arabic{infobox}}
    \makeatother

    However I can not get the vertical space as in the list of figures and tables that Latex put by default. I thought by modifying \@chapter slightly to add automatically vertical spacing to the .lob file after each \chapter starts would fix it, but it is not the case (I am using \documentclass[twoside]{book}).

    Thank you for your help.

    Regards.

    • tom

      Hi Fernando,

      Thanks for your question. I ran your code and the list of boxes looks exactly like the list of tables in my minimal example below, with some extra space to separate entries from different chapters. Also, above you say the space should be between sections and below you say between chapters. Could you clarify please.

      Thanks,
      Tom

       \documentclass[twoside]{book}
      \newcommand\dummytable{\begin{table}\caption{default}\end{table}}
      \begin{document}
      \tableofcontents
      \listoftables
      \chapter{Introduction}
      \section{First}
      \dummytable
      \section{Second}
      \dummytable
      \chapter{Methods}
      \section{First}
      \dummytable
      \section{Second}
      \dummytable\dummytable
      \end{document}
      • Fernando

        Thank you ver much Tom, I am sorry for the confusion. I meant the space between the names of tables and figures when you print the index of tables and figures.
        They have an extra space between chapters, something that I have not been able to reproduce when I print the list of boxes, which I tried by using \addtocontents{lob}{\protect\addvspace{10\p@}}.
        Best Regards.

      • tom

        If I run you code, the command patch works and I do get the extra vertical space between entries from different chapters. Please check if you have a recent version of LaTeX installed and update if necessary. If that’s not the issue, please post a complete minimal example.

        Best, Tom

        \documentclass[11pt]{book}
        \usepackage{blindtext}
        % Your code goes here
        \begin{document}
        \listofboxes
        \chapter{Intro}
        \section{First}
        \begin{infobox}[Introbox]
        \blindtext
        \end{infobox}
        \section{Second}
        \begin{infobox}[Introbox]
        \blindtext
        \end{infobox}
        \chapter{Methods}
        \begin{infobox}[Methods box]
        \blindtext
        \end{infobox}
        \end{document}
      • Fernando

        I did not want to put the complete code but as you requested I put it here.
        Maybe in some of the lines something makes the problem that happens in \addcontentsline{toc}{chapter}{ÍNDICE DE RECUADROS} at the very end:

        […]Code removed by Tom[…]

      • tom

        I didn’t request your complete code. I asked for a minimal example, which illustrates your problem in a few lines of code. Please try to provide that and I’ll be happy to take a look.

        Thanks, Tom

  7. Hello Sir,

    I am using Tex Maker
    Now the problem is list of figures and list of tables.
    In it the many of the names of the figures and tables are very long, so the names are going out of the pages instead of coming in the line below it. I suppose the problem lies in the width of the column in the list of figures and list of tables.

    I know how to change the width of a normal table inside. But I dont know how to deal with this problem of long names going out of the page for this.

    Please urgent help is required.

    • tom

      Hi Shaival,

      Thanks for your question. I’ve heard this a couple of times. Normally, line-breaks are automatically added in the LOF/LOT. Therefore, I can’t replicate the problem. Please provide a minimal working example to illustrate the issue. In general, I prefer to have a short version of the caption (e.g. first sentence) to be reproduced in the list of figures/tables. You can do this through the optional argument to caption.

      \caption[LOF/LOT short version]{Full caption text.}

      HTH,
      Tom

Leave a Reply to tom Cancel reply