welcome here. Before getting to your problem, first a gentle and well-meaning reminder (actually two):
- Please provide a fully worked minimal example with all submissions. Code fragments such as yours don't cut it since they leave room to keep people guessing, hopping in wrong directions, and wasting very precious time.
- Please provide only one problem per question. The danger you run into if you don't (as I'm sure has happened here), is that i) you double the work for answer-providers, and ii) the quality of the answers you'll receive will be limited to the quality of the best joint answer, which might very well be lower than the quality you'll get for separate answers (take note, my answer might fall into that category too!).
OK, with that out of the way, here are solutions to your problems.
Problem 1 -- a) Badly behaved margin figures captions and b) caption fontsize smaller
I couldn't reproduce your misbehaved margin figures captions, probably because I automatically used the caption and graphicx packages whereas you might not have done so. Nevertheless, without seeing the code you used, I'm at a loss to explain why your work turned out the way it did.
Setting the caption fontsize smaller (and many, many useful things besides) can be achieved with the \captionsetup
command from the caption package.
Here's an example of the output my code produces (code included below):
![alt text](https://i.stack.imgur.com/jojkw.png)
Problem 2 -- Subfig caption in wrapfig environment constrained to typeblock
Because you wanted subfigures to protrude into the margins, you created 0.3\textwidth
-wide wrapfigure
environments and then proceeded to place 0.5\textwidth
-wide figures into them. This gives the effect you want with your figures -- they spill nicely into the margins -- but, unfortunately, LaTeX wraps the overall figure caption to the page typeblock, giving you the most visually unappealing caption "clipping" effect that you see.
The solution's simple enough, if not entirely obvious. Use the optional 'overhang' argument with each invocation of wrapfigure
. (I set the margin protrusion to [3cm]
in the code below). Note also that to avoid overfull hboxes, I set the wrapfigure
environment width a little larger than the contained object width: 0.46\textwidth
to 0.45\textwidth
, respectively, below.)
Tidying up your code, I recommend:
- passing
\vspace
(negative) heights specified in terms of \baselineskip
rather than absolute pointsize dimensions when it comes to aligning objects with lines of text (this is just habit in this case, absolute dimensions will be fine),
- instructing
wrapfigure
to use an exact number of lines (in our case [33]
) to force it to more exactly meet your needs, and
- setting the typeblock-to-
wrapfigure
distance explicitly, e.g., with something like \setlength\columnsep{\marginparsep}
.
Here's the output from the code below:
![alt text](https://i.stack.imgur.com/J5jQr.png)
Solution code
\documentclass[twoside]{article}
\usepackage{graphicx}
\usepackage[dvipsnames]{xcolor}
\usepackage{caption}[2008/04/01]
\usepackage{wrapfig}
\usepackage{subfig}
\usepackage{lipsum} % to provide "filler" text
\captionsetup{
justification=raggedright,
labelfont={color=Maroon,bf},
font=small}
\begin{document}
\lipsum[1-2]
% Three marginpar figures to see how this looks in
% the left and right margins of twoside docs...
\marginpar{\includegraphics[width=0.95\marginparwidth]{Carl_Friedrich_Gauss.jpg}
\captionof{figure}{Carl Friedrich Gauss, født 1777, er bedst kendt for normalfordelingen}}
\lipsum[1-2]
\marginpar{\includegraphics[width=0.95\marginparwidth]{Carl_Friedrich_Gauss.jpg}
\captionof{figure}{Carl Friedrich Gauss, født 1777, er bedst kendt for normalfordelingen}}
\lipsum[1-4]
\marginpar{\includegraphics[width=0.95\marginparwidth]{Carl_Friedrich_Gauss.jpg}
\captionof{figure}{Carl Friedrich Gauss, født 1777, er bedst kendt for normalfordelingen}}
\lipsum[5-6]
\lipsum[2]
\setlength\columnsep{\marginparsep}
\begin{wrapfigure}[33]{r}[3cm]{0.46\textwidth}
\vspace{-1.5\baselineskip}
\subfloat[Giveaway pr. beholder i procent]{\label{lbl1}
\includegraphics[width=0.45\textwidth]{test.png}}\par
\subfloat[Giveaway pr. beholder i procent]{\label{lbl2}
\includegraphics[width=0.45\textwidth]{test.png}}
\caption{Resultater for testsæt 1 blah blah blah blah blah blah blah.}
\end{wrapfigure}
\lipsum[11-14]
\end{document}
These option clashes happen when a package is requested to be loaded on two different positions, like by you and inside another package, but with different options. The package is loaded by the first \usepackage
(or its twin \RequirePackage
); it isn't loaded again when it is requested again. It simply can't be loaded a second time. Therefore the new options can be activated and previous options might conflict with the second usage. So LaTeX creates an error to report this issue to you.
The way to fix this is to declare the options beforehand using \PassOptionsToPackage{<options>}{<package>}
. Then they are used wherever the package is loaded.
\documentclass{article}
\usepackage{ifpdf}
\ifpdf
\PassOptionsToPackage{pdftex,usenames,dvipsnames}{color}
\usepackage[T1]{fontenc}
\usepackage{libertine} % most likely loads 'color' itself
%\usepackage{lmodern} % doesn't load 'color'
\usepackage{color}
\usepackage[pdftex]{graphicx}
\else
%\bye
\fi
\begin{document}
Hello, world!
\end{document}
I can't test it by myself, because I don't have the libertine
package installed.
PS:
I don't think you need to set pdftex
manually. Normally packages do a good job recognizing the driver by themselves. Also you might want to use the extended xcolor
package instead of color
.
Best Answer
If you want the caption of all margin figures to be smaller, you can create a custom
\marginpar
command which embed a custom caption setup. Like this: