Update third solution added using undocumented option calcwidth
of caption
mentioned in comment by the package author.
Two solutions
First solution
If you need to keep you current width setting for captions in the rest of the text then
you can issue a new \captionsetup
command just before each \captionof
command. Note that this is not as bad is it sounds as you can say
\captionsetup{width=0.8\linewidth}
in each of your cases. The point is that the value of the line width its determined by the current minipage
so this gives you 0.8
of the width of the current minipage
environment:
\documentclass[
11pt
]{scrartcl}
\usepackage{
tikz,
relsize,
amsmath,
booktabs,
tikz
}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[
labelfont=sf,
hypcap=false,
format=hang,
width=0.8\columnwidth
]{caption}
\usetikzlibrary{
calc,trees,shadows,positioning,arrows,chains,
decorations.pathreplacing,
decorations.pathmorphing,
decorations.shapes,
decorations.text,
shapes,
shapes.geometric,
shapes.symbols,
matrix,
patterns,
intersections,
fit}
\pgfdeclarelayer{background layer}
\pgfdeclarelayer{foreground layer}
\pgfsetlayers{background layer,main,foreground layer}
\tikzset{
>=latex
}
\begin{document}
\begin{figure}[btc]
\begin{minipage}[c]{0.48\linewidth}
\begin{center}
\captionsetup{width=0.8\linewidth}
\captionof{table}{Dataset for Something with an Arbitrary Caption to
Highlight the Problem}
\begin{tabular}{lrrrrr}
\toprule
Store & A & B & C & D & E \\
\cmidrule(r{0.125em}){1-1}%
\cmidrule(lr{0.125em}){2-2}%
\cmidrule(lr{0.125em}){3-3}%
\cmidrule(lr{0.125em}){4-4}%
\cmidrule(lr{0.125em}){5-5}%
\cmidrule(l{0.25em}){6-6}%
Input & 0.75 & 1 & 2 & 5 & 5\\
Output & 0.5 & 2 & 4 & 2 & 5\\
\bottomrule
\end{tabular}
\end{center}
\end{minipage}
\hfill
\begin{minipage}[c]{0.48\linewidth}
\begin{center}
\begin{tikzpicture}[font=\sffamily\small]
%
\draw[style=help lines,step=0.5cm] (0,0) grid (6,6);
%
\draw[->,thick] (-0.1,0) -- (6.5,0) node[midway,below=8pt]{Output}; %X-Achse
\draw[->,thick] (0,-0.1) -- (0,6.5) node[above=5pt]{Input}; %Y-Achse
%
\foreach \x in {0,1,...,6} \draw [thick](\x cm,-2pt) -- (\x cm,2pt);
\foreach \y in {0,1,...,6} \draw [thick](-2pt,\y) -- (2pt,\y);
%
\foreach \x in {0,1,...,6} \draw (\x cm, 0 cm) node[anchor=north]{\x} coordinate (x axis);
\foreach \y in {0,1,...,6} \draw (0 cm, \y cm) node[anchor=east]{\y} coordinate (y axis);
%
\draw
(0,0) coordinate (orig)
(0.75,0.5) coordinate (A)
(1,2) coordinate (B)
(2,4) coordinate (C)
(5,2) coordinate (D)
(5,5) coordinate (E)
;
%
\foreach \pt/\labpos in {A/right,D/below left,E/below}{
\fill (\pt) circle (2pt) node[\labpos=3pt,fill=white]{\pt};
};
\foreach \pt/\labpos in {B/above left,C/above left}{
\fill (\pt) circle (3pt) node[\labpos=3pt,fill=white]{\pt};
};
\end{tikzpicture}
\captionsetup{width=0.8\linewidth}
\captionof{figure}{Graphical Illustration of Dataset with an Arbitrary Caption to Highlight the Problem}
\end{center}
\end{minipage}
\end{figure}
\end{document}
Second solution
An alternative is to specify the caption structure via margin size rather than width, then you do not need to issue separate set-up commands each time:
\documentclass[
11pt
]{scrartcl}
\usepackage{
tikz,
relsize,
amsmath,
booktabs,
tikz
}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[
labelfont=sf,
hypcap=false,
format=hang,
margin=1cm,
]{caption}
\usetikzlibrary{
calc,trees,shadows,positioning,arrows,chains,
decorations.pathreplacing,
decorations.pathmorphing,
decorations.shapes,
decorations.text,
shapes,
shapes.geometric,
shapes.symbols,
matrix,
patterns,
intersections,
fit}
\pgfdeclarelayer{background layer}
\pgfdeclarelayer{foreground layer}
\pgfsetlayers{background layer,main,foreground layer}
\tikzset{
>=latex
}
\begin{document}
\begin{figure}[btc]
\begin{minipage}[c]{0.48\linewidth}
\begin{center}
%\captionsetup{width=0.8\linewidth}
\captionof{table}{Dataset for Something with an Arbitrary Caption to
Highlight the Problem}
\begin{tabular}{lrrrrr}
\toprule
Store & A & B & C & D & E \\
\cmidrule(r{0.125em}){1-1}%
\cmidrule(lr{0.125em}){2-2}%
\cmidrule(lr{0.125em}){3-3}%
\cmidrule(lr{0.125em}){4-4}%
\cmidrule(lr{0.125em}){5-5}%
\cmidrule(l{0.25em}){6-6}%
Input & 0.75 & 1 & 2 & 5 & 5\\
Output & 0.5 & 2 & 4 & 2 & 5\\
\bottomrule
\end{tabular}
\end{center}
\end{minipage}
\hfill
\begin{minipage}[c]{0.48\linewidth}
\begin{center}
\begin{tikzpicture}[font=\sffamily\small]
%
\draw[style=help lines,step=0.5cm] (0,0) grid (6,6);
%
\draw[->,thick] (-0.1,0) -- (6.5,0) node[midway,below=8pt]{Output}; %X-Achse
\draw[->,thick] (0,-0.1) -- (0,6.5) node[above=5pt]{Input}; %Y-Achse
%
\foreach \x in {0,1,...,6} \draw [thick](\x cm,-2pt) -- (\x cm,2pt);
\foreach \y in {0,1,...,6} \draw [thick](-2pt,\y) -- (2pt,\y);
%
\foreach \x in {0,1,...,6} \draw (\x cm, 0 cm) node[anchor=north]{\x} coordinate (x axis);
\foreach \y in {0,1,...,6} \draw (0 cm, \y cm) node[anchor=east]{\y} coordinate (y axis);
%
\draw
(0,0) coordinate (orig)
(0.75,0.5) coordinate (A)
(1,2) coordinate (B)
(2,4) coordinate (C)
(5,2) coordinate (D)
(5,5) coordinate (E)
;
%
\foreach \pt/\labpos in {A/right,D/below left,E/below}{
\fill (\pt) circle (2pt) node[\labpos=3pt,fill=white]{\pt};
};
\foreach \pt/\labpos in {B/above left,C/above left}{
\fill (\pt) circle (3pt) node[\labpos=3pt,fill=white]{\pt};
};
\end{tikzpicture}
%\captionsetup{width=0.8\linewidth}
\captionof{figure}{Graphical Illustration of Dataset with an Arbitrary Caption to Highlight the Problem}
\end{center}
\end{minipage}
\end{figure}
\end{document}
Third solution
The author, Axel Sommerfeldt, mentions in a comment that there is a new, undocument option to caption, which is calcwidth
. Testing this, it works well in your example, at least in the form calcwidth=0.8\linewidth
as package option. It recalculates the width specification at each use rather than fixing calculated value at the beginning of the document.
If you use calcwidth=0.8\columnwidth
, you have to be very careful about placement of commands switching numbers of columns. As your example is a one column layout, I will stick with the simple \linewidth
.
For illustration I have also added RaggedRight
to the captions. This allows some hyphenation, in contrast to raggedright
which will only break lines at word boundaries.
\documentclass[
11pt
]{scrartcl}
\usepackage{
tikz,
relsize,
amsmath,
booktabs,
tikz,ragged2e
}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[
labelfont=sf,
hypcap=false,
format=hang,
margin=1cm,
justification=RaggedRight,
calcwidth=0.8\linewidth
]{caption}
\usetikzlibrary{
calc,trees,shadows,positioning,arrows,chains,
decorations.pathreplacing,
decorations.pathmorphing,
decorations.shapes,
decorations.text,
shapes,
shapes.geometric,
shapes.symbols,
matrix,
patterns,
intersections,
fit}
\pgfdeclarelayer{background layer}
\pgfdeclarelayer{foreground layer}
\pgfsetlayers{background layer,main,foreground layer}
\tikzset{
>=latex
}
\begin{document}
\begin{figure}[btc]
\begin{minipage}[c]{0.48\linewidth}
\begin{center}
\captionof{table}{Dataset for Something with an Arbitrary Caption to
Highlight the Problem}
\begin{tabular}{lrrrrr}
\toprule
Store & A & B & C & D & E \\
\cmidrule(r{0.125em}){1-1}%
\cmidrule(lr{0.125em}){2-2}%
\cmidrule(lr{0.125em}){3-3}%
\cmidrule(lr{0.125em}){4-4}%
\cmidrule(lr{0.125em}){5-5}%
\cmidrule(l{0.25em}){6-6}%
Input & 0.75 & 1 & 2 & 5 & 5\\
Output & 0.5 & 2 & 4 & 2 & 5\\
\bottomrule
\end{tabular}
\end{center}
\end{minipage}
\hfill
\begin{minipage}[c]{0.48\linewidth}
\begin{center}
\begin{tikzpicture}[font=\sffamily\small]
%
\draw[style=help lines,step=0.5cm] (0,0) grid (6,6);
%
\draw[->,thick] (-0.1,0) -- (6.5,0) node[midway,below=8pt]{Output}; %X-Achse
\draw[->,thick] (0,-0.1) -- (0,6.5) node[above=5pt]{Input}; %Y-Achse
%
\foreach \x in {0,1,...,6} \draw [thick](\x cm,-2pt) -- (\x cm,2pt);
\foreach \y in {0,1,...,6} \draw [thick](-2pt,\y) -- (2pt,\y);
%
\foreach \x in {0,1,...,6} \draw (\x cm, 0 cm) node[anchor=north]{\x} coordinate (x axis);
\foreach \y in {0,1,...,6} \draw (0 cm, \y cm) node[anchor=east]{\y} coordinate (y axis);
%
\draw
(0,0) coordinate (orig)
(0.75,0.5) coordinate (A)
(1,2) coordinate (B)
(2,4) coordinate (C)
(5,2) coordinate (D)
(5,5) coordinate (E)
;
%
\foreach \pt/\labpos in {A/right,D/below left,E/below}{
\fill (\pt) circle (2pt) node[\labpos=3pt,fill=white]{\pt};
};
\foreach \pt/\labpos in {B/above left,C/above left}{
\fill (\pt) circle (3pt) node[\labpos=3pt,fill=white]{\pt};
};
\end{tikzpicture}
\captionof{figure}{Graphical Illustration of Dataset with an Arbitrary Caption to Highlight the Problem}
\end{center}
\end{minipage}
\end{figure}
\end{document}
\columnwidth
for any of this but rather\textwidth
. As for the caption with\linewidth
seems more appropriate asminipage
will set this. But it does not seem to work. Looks likewidth=0.8\linewidth
just takes the current value at that time to be the with, it does not readjust it from time to time. A simple experiment confirms this to be true.