Graphics, Figures & Tablescentering the caption under figure

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
kzg
Posts: 12
Joined: Fri Sep 03, 2010 5:51 pm

centering the caption under figure

Post by kzg »

Hello Latex profis,

i am doing the following:

Code: Select all

\documentclass[12pt, a4paper, oneside]{memoir}
\usepackage{graphicx}
\usepackage[OT4]{fontenc}
\usepackage[cp1250]{inputenc}
\begin{document}
\begin{figure}[h!]
\centering
\caption{a short topic is centered.}
\caption{a very long topic should be centered but somehow it is not. a very long topic should be centered but somehow it is not. a very long topic should be centered but somehow it is not.}
\end{figure}
\end{document}
Does please anybody have an idea what to do to center very long captions under figures (have the same problem with tables)? Maybe i have not included any important package?

thx in forward.

ps. i am using LEd under Windows XP
Last edited by kzg on Wed Sep 08, 2010 10:06 am, 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

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: centering the caption under figure

Post by localghost »

I don't see the problem. Both captions behave normal. The second one is just wrapped to fit the margins. Please be a little bit more specific.


Thorsten
kzg
Posts: 12
Joined: Fri Sep 03, 2010 5:51 pm

Re: centering the caption under figure

Post by kzg »

i have sent a pdf file with my result of the above code compilation. second caption is not centered. maybe the problem lies in the LEd?
Attachments
test.pdf
(4.41 KiB) Downloaded 493 times
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Re: centering the caption under figure

Post by localghost »

As I already said this behaviour is quite usual and has nothing to do with your editor. Perhaps you should clarify what you expect.
User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Re: centering the caption under figure

Post by frabjous »

It looks fine to me. Do you want the individual lines of the caption to be centered, even when wrapped? If so, then try adding the \centering command inside the \caption. I think that would be ugly, but if that's what appeals to you, go ahead.
kzg
Posts: 12
Joined: Fri Sep 03, 2010 5:51 pm

centering the caption under figure

Post by kzg »

Here the code one again:

Code: Select all

\documentclass[12pt, a4paper, oneside]{memoir}
\usepackage{graphicx}
\usepackage[OT4]{fontenc}
\usepackage[cp1250]{inputenc}
\begin{document}
\begin{figure}[h!]
\centering
\caption{a short topic is centered.}
\caption {a very long topic should be centered but somehow it is not. a very long topic should be centered but somehow it is not. a very long topic should be centered but somehow it is not.}
\end{figure}
\begin{center} a very long sentence which is centered, a very long sentence which is centered, a very long sentence which is centered, a very long sentence which is centered, a very long sentence which is centered, a very long sentence which is centered.\end{center}
\end{document}
puting \centering inside the caption{...} creates compilation errors :)

a word of explanation: my supervisor wants me to make all captions in my thesis to be centered. He is a MS Word fan, so i am looking for the solution in order to prove him that latex is better and can everythig ;)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

centering the caption under figure

Post by localghost »

The memoir class offers an appropriate mechanism to get the desired result. See the class manual for details (Section 10.6 — Caption styling, p. 187ff).

Code: Select all

\documentclass[12pt,a4paper,oneside]{memoir}
\usepackage[OT4]{fontenc}
\usepackage[cp1250]{inputenc}

\captionstyle{\centering}

\begin{document}
  \begin{figure}[!ht]
    \centering
    \rule{6.4cm}{3.6cm}
    \caption{a very long topic should be centered but somehow it is not. a very long topic should be centered but somehow it is not. a very long topic should be centered but somehow it is not.}
  \end{figure}
\end{document}
You may take a look at the ragged2e package for an enhanced \Centering command.
kzg
Posts: 12
Joined: Fri Sep 03, 2010 5:51 pm

Re: centering the caption under figure

Post by kzg »

now it is as i want it to be.

Thank you a lot!!!
Post Reply