2

I want to align captions to left side of the figures and tables. After this, I want to align caption's first line to second line. My MWE is below, could you help me to solve the issue?

Desired solutions are given below as image. Thank you.

enter image description here enter image description here

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tabularx}

\title{Title}

\begin{document}
\maketitle

\section{Introduction}

\begin{figure}[h!]
  \centering
  \includegraphics[height=7cm]{indir.jpg}
  \caption[Lorem ipsum dolor sit amet]{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed felis risus, ullamcorper ac suscipit ac, molestie non orci. Nam neque orci, facilisis in euismod sed, suscipit quis dolor.}
  \label{fig:heyelenturkiye}
\end{figure}


\begin{table}[!h]
\small
\centering
\caption[Lorem ipsum dolor sit amet]{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed felis risus, ullamcorper ac suscipit ac, molestie non orci. Nam neque orci, facilisis in euismod sed, suscipit quis dolor\\}
\begin{tabular}{cccc}
\hline
Row1    & Row2  & Row3  & Row4\\
\hline
Lorem & ipsum & dolor & sit \\
Lorem & ipsum & dolor & sit \\
Lorem & ipsum & dolor & sit \\
Lorem & ipsum & dolor & sit \\
\hline
\end{tabular}
\label{t1}
\end{table}

\end{document}
  • How wide should the captions be? As wide as the image/tabular or all the way from the left side of the image/tabular to the right margin? – leandriis Jun 12 at 19:50
  • @leandriis there is any limitation for wideness. Captions are wide as normal text. – volkan Jun 12 at 19:53
  • And If it is important, I wrote article in MWE but document class is report. – volkan Jun 12 at 19:57
  • 1
    Regarding the second part of the question: Add \usepackage{caption} \captionsetup{format=hang} to the preamble. – leandriis Jun 12 at 19:57
  • @leandriis Thank you, it works! Any idea for the first questions? – volkan Jun 12 at 20:00
1

Well, I defined two macros, one for figures (\weirdCapFigure) and another for the tables (\weirdCapTable). The first macro accepts the image as its first argument and the caption as its second argument, the second macro works with the reversed order, i.e., the caption first. I also followed the advice of @leandriis about using the caption package.

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tabularx}

\usepackage{caption} 
\captionsetup{format=hang}

\title{Title}

\begin{document}

\section{Introduction}

\newcommand{\weirdCapFigure}[2]{\sbox{0}{#1}#1
  \rule{\dimexpr.5\linewidth-0.5\wd0}{0pt}%
  \parbox[t]{\dimexpr.5\linewidth+0.5\wd0}{\caption{#2}}
}
\newcommand{\weirdCapTable}[2]{\sbox{0}{#2}
  \rule{\dimexpr.5\linewidth-0.5\wd0}{0pt}%
  \parbox[t]{\dimexpr.5\linewidth+0.5\wd0}{\caption{#1}}
  #2%
}

\begin{figure}[h!]
  \centering
  \weirdCapFigure{\includegraphics[height=7cm]{example-image}}
  {Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed felis risus, ullamcorper ac suscipit ac, molestie non orci. Nam neque orci, facilisis in euismod sed, suscipit quis dolor.\label{fig:heyelenturkiye}}  
\end{figure}


\begin{table}[!h]
\small
\centering
\weirdCapTable{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed felis risus, ullamcorper ac suscipit ac, molestie non orci. Nam neque orci, facilisis in euismod sed, suscipit quis dolor.\label{t1}}
{\begin{tabular}{cccc}
\hline
Row1    & Row2  & Row3  & Row4\\
\hline
Lorem & ipsum & dolor & sit \\
Lorem & ipsum & dolor & sit \\
Lorem & ipsum & dolor & sit \\
Lorem & ipsum & dolor & sit \\
\hline
\end{tabular}}
\end{table}

\end{document}

enter image description here

  • Thank you @AboAmmar It works very well. In the report I use caption command with this code \caption[Lorem ipsum]{Lorem ipsum dolor sit}. [Lorem ipsum] section is shown in TOC and {Lorem ipsum dolor sit} section is shown in the report. I am realized that I did not ask the question with [Lorem ipsum]. When I try to use [Lorem ipsum], I get an error messages. Could you please help with this issue too? Thank you. – volkan Jun 13 at 7:08
  • By the way, I've edited the questions to include paranthesis [ ]. – volkan Jun 13 at 7:14
0

A workaround (but not the complete desired solution) is just deleting \centering:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{tabularx}

\usepackage{caption} 
\captionsetup{format=hang}
\title{Title}

\begin{document}
\maketitle

\section{Introduction}

\begin{figure}[h!]
%  \centering
  \includegraphics[height=7cm]{example-image-a}
  \caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed felis risus, ullamcorper ac suscipit ac, molestie non orci. Nam neque orci, facilisis in euismod sed, suscipit quis dolor.}
  \label{fig:heyelenturkiye}
\end{figure}


\begin{table}[!h]
\small
%\centering
\caption{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed felis risus, ullamcorper ac suscipit ac, molestie non orci. Nam neque orci, facilisis in euismod sed, suscipit quis dolor\\}
\begin{tabular}{cccc}
\hline
Row1    & Row2  & Row3  & Row4\\
\hline
Lorem & ipsum & dolor & sit \\
Lorem & ipsum & dolor & sit \\
Lorem & ipsum & dolor & sit \\
Lorem & ipsum & dolor & sit \\
\hline
\end{tabular}
\label{t1}
\end{table}

\end{document}

enter image description here enter image description here

  • Thank you for an alternative but images and tables must be in the center of the paper. /: – volkan Jun 12 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.