LyXSubfigure without number [solved]

Information and discussion about LyX, a WYSIWYM editor, available for Linux, Windows and Mac OS X systems.
roby92ita
Posts: 10
Joined: Mon Feb 13, 2017 11:32 am

Subfigure without number [solved]

Post by roby92ita »

Hi, I'm new in the forum. I'm writing my thesis using LyX, v. 2.2.2, and I've got a problem with subfigures.
I'd like to recall the label in the description of the Figure like (a) and (b), but using the cross reference I have 1(a) and 1(b); instead in the text I want exactly 1(a) and 1(b). Like:


(a) graph1 (b) graph2
Figure 1: (a) graph1 and explanation, (b) graph2 and explanation

In fig. 1(a) there's the graph1 about...

I've tried using \subref command, and it works but with an error: "Argument of \caption@ydblarg has an extra }." that I don't understand.
There's some method to overcome this problem? I've searched trough the forum but without result.
I hope I explained myself well.
Last edited by roby92ita on Mon Feb 20, 2017 10:27 am, edited 2 times 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

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Subfigure without number [solved]

Post by Stefan Kottwitz »

Hi Roby,

welcome to the forum!

Do you use the subfigure package, or subfig? I recommend the latter, since that one is newer.
Maybe take a look at the (here linked) package manual how that works.

Stefan
LaTeX.org admin
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Subfigure without number [solved]

Post by Johannes_B »

Package subcaption is even better with respect to hyperlink support.
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
roby92ita
Posts: 10
Joined: Mon Feb 13, 2017 11:32 am

Subfigure without number

Post by roby92ita »

Thanks everyone,
the package subcaption is in conflict with the package subfigure that is automatically used by LyX and I don't know how to remove it.
With the package subfig I have the exact problem that i described, maybe it is because I use the insert Image and Insert Label of Lyx instead of using the ERT to load the image?
scottkosty
Site Moderator
Posts: 542
Joined: Sat Sep 01, 2012 6:38 am

Subfigure without number

Post by scottkosty »

Can you post a minimal example where you get the conflict in LyX? If so I can take a look.
roby92ita
Posts: 10
Joined: Mon Feb 13, 2017 11:32 am

Subfigure without number

Post by roby92ita »

I made a little file showing what I want to do, hope it help understanding the problem.
The conflict appear when I put in the Preamble \usepackage{caption}, so if you put that in the Preamble of my file I think you'll get the same problem.
Thanks
Attachments
Test.rar
(14.92 KiB) Downloaded 295 times
scottkosty
Site Moderator
Posts: 542
Joined: Sat Sep 01, 2012 6:38 am

Subfigure without number

Post by scottkosty »

I know how to disable loading the subfig package in LyX, but then \subfloat is not defined. What do you ideally want the LaTeX output to look like? Perhaps you could post what LyX creates as LaTeX and what you wish it would be. Then I can see if it is possible to have LyX do it.
roby92ita
Posts: 10
Joined: Mon Feb 13, 2017 11:32 am

Subfigure without number [solved]

Post by roby92ita »

Thanks, LyX generate:

Code: Select all

%% LyX 2.2.2 created this file.  For more info, see http://www.lyx.org/.
%% Do not edit unless you really know what you are doing.
\documentclass[12pt,twoside,italian]{article}
\usepackage[T1]{fontenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=25mm,bmargin=25mm,lmargin=25mm,rmargin=25mm}
\usepackage{babel}
\usepackage{graphicx}
\usepackage{setspace}
\onehalfspacing
\usepackage[unicode=true,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
 {hyperref}
\hypersetup{pdftitle={Tesi di Roberto Sciacqua},
 pdfauthor={Roberto Sciacqua},
 pdfkeywords={Ingegneria, meccanica}}

\makeatletter
\@ifundefined{showcaptionsetup}{}{%
 \PassOptionsToPackage{caption=false}{subfig}}
\usepackage{subfig}
\makeatother

\begin{document}
\begin{figure}
\begin{centering}
\subfloat[\label{fig:cat}a cat]{\includegraphics{cat}

}\subfloat[\label{fig:dog}a dog]{\includegraphics{dog}

}
\par\end{centering}
\caption{\label{fig:two-animals}two animals: \subref{fig:cat} a jumping cat,
\subref{fig:dog} a dog}
\end{figure}

In fig. \ref{fig:two-animals} is it possible to see two animals,
in fig. \ref{fig:cat} a jumping cat, in fig. \ref{fig:dog} a dog
playing with a ball.
\end{document}
Instead I want something like this (or at least that make the same output):

Code: Select all

\documentclass[12pt,twoside,italian]{article}
\usepackage[T1]{fontenc}
\usepackage[a4paper]{geometry}
\geometry{verbose,tmargin=25mm,bmargin=25mm,lmargin=25mm,rmargin=25mm}
\usepackage{babel}
\usepackage{graphicx}
\usepackage{setspace}
\onehalfspacing
\usepackage[unicode=true,
 bookmarks=true,bookmarksnumbered=false,bookmarksopen=false,
 breaklinks=false,pdfborder={0 0 1},backref=false,colorlinks=false]
 {hyperref}
\hypersetup{pdftitle={Tesi di Roberto Sciacqua},
 pdfauthor={Roberto Sciacqua},
 pdfkeywords={Ingegneria, meccanica}}

\usepackage{subfig}

\begin{document}
\begin{figure}
\centering
\subfloat[][a cat]{\label{cat}\includegraphics{cat}}
\subfloat[][a dog]{\label{dog}\includegraphics{dog}}
\caption[Two animals]{two animals: \subref{cat} a jumping cat,
 \subref{dog} a dog}
\label{two-animals}
\end{figure}

In fig. \ref{two-animals} is it possible to see two animals,
in fig. \ref{cat} a jumping cat, in fig. \ref{dog} a dog
playing with a ball.
\end{document}
scottkosty
Site Moderator
Posts: 542
Joined: Sat Sep 01, 2012 6:38 am

Subfigure without number

Post by scottkosty »

Take a look at the attached .lyx file. I think it gets close to what you want. A few things to note:

1. In Document > Settings > Local Layout, I put "Provides subfig 1". This basically tells LyX "don't worry about automatically loading this, I will do it myself"
2. In the LaTeX Preamble, we load the package.
3. There is some ERT required for e.g. "\subref{cat}", which is not very elegant. This will be improved a bit in LyX version 2.3 (still not close to being released), where you can enter a label directly. With that improvement, we could make a custom inset for "\subref" and no ERT would be required.
Attachments
dog.jpg
dog.jpg (8.14 KiB) Viewed 14658 times
cat.jpg
cat.jpg (4.5 KiB) Viewed 14658 times
test.lyx
(3.9 KiB) Downloaded 444 times
roby92ita
Posts: 10
Joined: Mon Feb 13, 2017 11:32 am

Subfigure without number

Post by roby92ita »

It's perfect like this, thanks a lot!
Post Reply