Graphics, Figures & TablesChange of justification to \justified in figure captions

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
vichome
Posts: 3
Joined: Wed Dec 19, 2012 11:24 pm

Change of justification to \justified in figure captions

Post by vichome »

Hi,

How can I change the justification from centered to justified in figure captions?

Document class I use: revtex4-1
Tex Live for Mac

Revtex4-1 does not support the caption package I am using, and the \usepackage command is of no use: justification does change from the original \centered to \raggedright, but not to justified:

Code: Select all

\usepackage[labelfont=bf,labelsep=quad,justification=justified]{caption}
The \Declare command does not help either:

Code: Select all

\DeclareCaptionJustification{justified}{\justified}
Can the problem be solved by \renew commands? If it can and if someone can help, I need a sufficiently detailed description

Many thanks in advance and happy Christmas!
Victor
Last edited by cgnieder on Fri Dec 21, 2012 4:58 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Change of justification to \justified in figure captions

Post by cgnieder »

Hi Victor,

Welcome to the LaTeX community!

As you've already found out caption is not aware of the »revtex4-1« class. I don't think it's easy for a user to change that. I wouldn't use it at all but instead change the internal macro that is responsible for the typesetting of the caption:

Code: Select all

\documentclass{revtex4-1}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage{lipsum}% for dummy text

\makeatletter
\renewcommand\@make@capt@title[2]{%
 \@ifx@empty\float@link{\@firstofone}{\expandafter\href\expandafter{\float@link}}%
  {\textbf{#1}}\@caption@fignum@sep#2\quad
}%
\makeatother

\begin{document}

\lipsum[1]

\begin{figure}[ht]
 \rule{5cm}{3cm}
 \caption{\protect\lipsum[2]}
 \label{fig:foo}
\end{figure}

\lipsum[3]

\end{document}
Since the »revtex4-1« class seems to be designed for articles submitted to the American Physical Society or the American Institute of Physics, the captions are designed exactly the way they want it. Why do you want to change them, then? (Or aren't you using the class to submit an article to them?)

Regards
site moderator & package author
vichome
Posts: 3
Joined: Wed Dec 19, 2012 11:24 pm

Change of justification to \justified in figure captions

Post by vichome »

Thanks, Clemens -- but I was unable to get the result using the code, even after numerous attempts.

Code: Select all

\makeatletter
    \renewcommand\@make@capt@title[2]{%
     \@ifx@empty\float@link{\@firstofone}{\expandafter\href\expandafter{\float@link}}%
      {\textbf{#1}}\@caption@fignum@sep#2\quad}%
    \makeatother
What I did was to put the code in the preample. I commented the previously used \caption but the other things remained the same, correct?

Code: Select all

(\begin{figure} ... \caption ... \end{figure})

LaTeX reacted to this by changing Figure 1--no full stop -- \quad to FIG. 1. But justification did not change to justified.

Could you please tell where I can find information on the \caption package for TeX Live 2011/2012 to read about the TeX Live inherent caption package?

Your message prompted me to just use \hfil to spread the words along the line so that the figure captions look like justified. I do need to understand how TeX Live's intrinsic \caption works, though, and would appreciate your advice on that.

Frohe Weinachten!

Victor
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Change of justification to \justified in figure captions

Post by cgnieder »

vichome wrote:Thanks, Clemens -- but I was unable to get the result using the code, even after numerous attempts.
Could you then post a Infominimal working example (similar to what I posted, i.e., beginning with \documentclass and ending with \end{document}) so I (or someone else) can see what is going on?
vichome wrote:Could you please tell where I can find information on the \caption package for TeX Live 2011/2012 to read about the TeX Live inherent caption package?
There are in principle two main ways to find information on a package. The first: look on your own computer where the documentation is probably installed. A command line call of the following:

Code: Select all

texdoc caption
should open the caption documentation for instance. If it isn't there there's also http://texdoc.net:

Code: Select all

http://texdoc.net/pkg/caption
should also open the documentation.

Second there's always CTAN (the Comprehensive TeX Archive Network):

Code: Select all

http://www.ctan.org/pkg/caption
vichome wrote:Frohe Weinachten!
Thanks! Merry Christmas to you, too

Regards
site moderator & package author
vichome
Posts: 3
Joined: Wed Dec 19, 2012 11:24 pm

Change of justification to \justified in figure captions

Post by vichome »

Now your code works! Probably, I missed something when inserting it. Anyway, I have prepared an MWE and would put it on display -- it could be useful to others...

Code: Select all

\documentclass[twoside,rmp, ams]{revtex4-1} 
\usepackage{amsmath, amsfonts, amssymb}
\usepackage{graphicx}

%%%%%%%%%%%%%%%%%        Clemens (Latex Community)
%    \documentclass{revtex4-1}          %%%%%%%%%%%%% 
%    \usepackage[utf8]{inputenc}         %%%%%%%%%%%%%
%    \usepackage[T1]{fontenc}             %%%%%%%%%%%%%
%
%    \usepackage{lipsum}% for dummy text   %%%%%%%%%%%%%

%    \makeatletter                                %%%%%%%%%%%%%
%    \renewcommand\@make@capt@title[2]{%
%     \@ifx@empty\float@link{\@firstofone}{\expandafter\href\expandafter{\float@link}}%
%      {\textbf{#1}}\@caption@fignum@sep#2\quad}%
%    \makeatother
%%%%%%%%%%%%%%%%%          Clemens (Latex Community)

  \makeatletter
    \renewcommand\@make@capt@title[2]{%
     \@ifx@empty\float@link{\@firstofone}{\expandafter\href\expandafter{\float@link}}%
      {\textbf{#1}}\@caption@fignum@sep#2\quad}%
    \makeatother
   
\makeatletter 
\renewcommand{\fnum@figure}{\textbf{Figure~\thefigure}}
\makeatother

\begin{document}

Text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text 

\begin{figure}[h]              
\rule{5cm}{3cm}
\caption{Capt to be justif  Caption to be justified Caption to be justified Caption to be justified Caption to be justified Caption to be justified Caption to be justified Caption to be justified Caption to be justified Caption to be justified Caption to be justified Caption to be justified Caption to be justifiedCaption to be justifiedCaption to be justifiedCaption to be justifiedCaption to be justifiedCaption to be justifiedCaption to be justifiedCaption to be justified.}
\end {figure}

\end{document}
Thanks a lot!
Post Reply