Graphics, Figures & TablesHow to add dashed line in figure caption

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
Funny_w
Posts: 5
Joined: Fri Jan 13, 2017 10:24 am

How to add dashed line in figure caption

Post by Funny_w »

Hi guys,
How to add various dashed line in figure caption in Latex like the figure attached? I have tried for hours but not succeed.

Funny_w
Attachments
QQ截图20170317173641.png
QQ截图20170317173641.png (81.84 KiB) Viewed 18718 times
Last edited by Funny_w on Mon Mar 20, 2017 3:40 pm, edited 1 time in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
TikZ book
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

How to add dashed line in figure caption

Post by cgnieder »

What exactly did you try for hours? Using TikZ this is pretty straightforward:

Code: Select all

\documentclass{article}
\usepackage{tikz,siunitx}
\begin{document}

Receiver distances
\tikz[baseline]{\draw[thick] (0,.5ex)--++(.5,0) ;}~\SI{.1}{\meter},
\tikz[baseline]{\draw[dashed] (0,.5ex)--++(.5,0) ;}~\SI{.5}{\meter},
\tikz[baseline]{\draw[densely dashed] (0,.5ex)--++(.5,0) ;}~\SI{1}{\meter},
\tikz[baseline]{\draw[dash dot] (0,.5ex)--++(.5,0) ;}~\SI{2}{\meter},
\tikz[baseline]{\draw[dash dot dot] (0,.5ex)--++(.5,0) ;}~\SI{5}{\meter},
\tikz[baseline]{\draw (0,.5ex)--++(.5,0) ;}~\SI{100}{\meter}
(after ...)

\end{document}
Admittedly the manual (pgfmanual) is rather long, but…

Regards
site moderator & package author
Funny_w
Posts: 5
Joined: Fri Jan 13, 2017 10:24 am

How to add dashed line in figure caption

Post by Funny_w »

Dear cgnieder,

Yes, I did try it for a long time but still did not solve this problem.
Your code works well in the document environment. But it does not work in the caption environment even use the command \protect. In the pgfmanual a case was listed like this:

Code: Select all

\begin{figure}
\beginpgfgraphicnamed{graphic-of-flat-world}
\begin{tikzpicture}
\fill (0,0) circle (1cm);
\end{tikzpicture}
\endpgfgraphicnamed
\caption{The flat world.}
\label{fig1}
\end{figure}
Is the tikz and the caption environment incompatible? I still be confused...
Anyway, as a freshman, I still learn much from your code.


Yours Sincerely
Funny_w
User avatar
Stefan Kottwitz
Site Admin
Posts: 10315
Joined: Mon Mar 10, 2008 9:44 pm

How to add dashed line in figure caption

Post by Stefan Kottwitz »

Hello,

the TikZ code in the caption breaks when it's moved to the list of figures. Use a short version without TikZ code:

\caption[optional short text]{text with TikZ}

Stefan
LaTeX.org admin
Funny_w
Posts: 5
Joined: Fri Jan 13, 2017 10:24 am

How to add dashed line in figure caption

Post by Funny_w »

Dear cgnieder and Stefan Kottwitz,

Thanks to your warm reply!

I realized the key point of this problem, in the caption of figure environment, both of the two commands should be add by a /protect.
So the final code based cgnieder' is followed.

Code: Select all

\begin{figure*}[!htb]
	\begin{center}
		\includegraphics[width=0.4\paperwidth]{figures/4_13.jpg}
	\end{center}
	\caption{ \label{fig:4_13}Effect of receiver arc ...eiver distances
	 \protect\tikz[baseline]{\protect\draw[line width=1mm] (0,.8ex)--++(1,0) ;}~\SI{.1}{\meter},
	 \protect\tikz[baseline]{\protect\draw[line width=0.5mm,loosely dashed] (0,.8ex)--++(1,0) ;}~\SI{.5}{\meter},
	 \protect\tikz[baseline]{\protect\draw[line width=0.5mm,densely dashed] (0,.8ex)--++(1,0);}~\SI{1}{\meter},
	 \protect\tikz[baseline]{\protect\draw[line width=0.5mm,dash dot] (0,.8ex)--++(1,0) ;}~\SI{2}{\meter}, 
	 \protect\tikz[baseline]{\protect\draw[line width=0.5mm,dash dot dot] (0,.8ex)--++(1,0) ;}~\SI{5}{\meter}, 
	 \protect\tikz[baseline]{\protect\draw[line width=0.5mm] (0,.8ex)--++(1,0) ;}~\SI{100}{\meter} (after Hargreaves et al.7). }
\end{figure*}
and the result is almost the same as the figure i uploaded.
1.png
1.png (41.55 KiB) Viewed 18559 times

Finally, thanks to you both and the community. You are the first ones when I meet a problem and seek the help from.


Sincerely
Funny_w
Post Reply