Expanding my comment, as requested by the OP, the idea is to force the bounding box of each figure to the region containing the included figure. This is easy, because the figure is included in a node.
If the name of the node is c
, for example, you only have to include the following path as part of the tikzpicture
:
\path[use as bounding box] (c.south west) rectangle (c.north east);
This rectangle is what is taken into account by TeX in order to reserve space for the figure, and thus for alignment. All what is drawn outside of that rectangle, "spills out" the tikz picture, and can overlap the surrounding text. To avoid this you have to set manually some vertical or horizontal space around the tikz picture.
In your example, subfigure (c) has to be "manually" shifted down to avoid the rotated labels at top to collide with figures (a) and (b). This means to insert some \vskip
between them.
This is the complete code (the changes are marked with % <===
comments)
\documentclass{scrartcl}
\usepackage{xcolor}
\usepackage{caption}
\usepackage{floatrow}
\usepackage{subcaption}
\usepackage[demo]{graphicx}
\usepackage[framemethod=tikz]{mdframed}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees,calc,decorations.markings}
\begin{document}
\begin{figure}
\begin{mdframed}[
align=center,
linecolor=black,
fontcolor=black,
backgroundcolor=white,
userdefinedwidth=0.9\textwidth,
roundcorner=5pt,
skipabove=0pt,
skipbelow=0pt,
leftmargin=0pt,
innerleftmargin=20pt,
innerrightmargin=0pt,
innertopmargin=5pt,
innerbottommargin=5pt,
innerlinewidth=0pt,
middlelinewidth=0pt,
outerlinewidth=1pt]
\floatsetup[subfigure]{captionskip=10pt}
%===================== upper two subfigures ================
\begin{minipage}{.44\textwidth}
\begin{subfigure}{\linewidth}
\centering
\begin{tikzpicture}[remember picture]
\node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (a) {\includegraphics[width=5cm, height=5cm, clip= true, trim = 0 0 0 → 0]{whatever}};
\end{tikzpicture}
\begin{tikzpicture}[remember picture]
\node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (asupp) {\includegraphics[width=5cm,height=.75cm, clip= true, trim = 0 → 0 0 0]{whatever}};
\end{tikzpicture}
\caption{Image}
\label{fig:mwe:a}
\end{subfigure}\\[0ex]
\end{minipage}
\begin{minipage}{.44\textwidth}
\begin{subfigure}{\linewidth}
\centering
\begin{tikzpicture}[remember picture]
\node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (b) {\includegraphics[width=5cm, height=5cm, clip= true, trim = 0 → 0 0 0]{whatever}};
\end{tikzpicture}
\begin{tikzpicture}[remember picture]
\node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (bsupp) {\includegraphics[width=5cm, height=.75cm, clip= true, → trim = 0 0 0 0]{whatever}};
\end{tikzpicture}
\caption{Image}
\label{fig:mwe:b}
\end{subfigure}
\end{minipage}
\vskip 2cm % <==== Needed to "make room" for the rotated labels
%===================== the one below subfigure ================
\begin{minipage}{.94\textwidth}
\begin{subfigure}{\linewidth}
\centering
\begin{tikzpicture}[remember picture]
\node [anchor=south west,draw=orange,line width=5pt, inner sep=0pt] (c)
{\includegraphics[width=5cm, height=5cm, clip= true, trim = 35 0 0 0]{whatever}};
\path[use as bounding box] (c.south west) rectangle (c.north east); % <=====
\path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,.2); %arrowhead
\path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,1.6);
\path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,3);
\path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,3.6);
\path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,4.1);
\path [decoration={markings, mark=at position 1 with {\arrow[scale=2,rotate=180]{latex}}}, decorate] (5.1,4.6);
% add labels
\node [anchor=south west, xshift=35pt, rotate=45] at (c.north west) {Lane1 ABC};
\node [anchor=south west, xshift=70pt, rotate=45] at (c.north west) {Lane2 DEF};
\node [anchor=south west, xshift=105pt, rotate=45] at (c.north west) {Lane3 GHI};
\node [anchor=south west, xshift=135pt, rotate=45] at (c.north west) {Lane4 JKL};
\end{tikzpicture}
\\[0ex]
\begin{tikzpicture}[remember picture]
\node [anchor=south west, draw=orange,line width=5pt, inner sep=0pt] (csupp) {\includegraphics[width=5cm, height=.75cm, clip= true, trim = → 0 0 0 0]{whatever}};
\path[use as bounding box] (csupp.south west) rectangle (csupp.north east); % <======
\node[anchor=south west,font=\ttfamily,xshift=-50] at (csupp.south west) {$\beta$-actin};
\end{tikzpicture}
\\[0ex]
\caption{Image}
\label{fig:mwe:c}
\end{subfigure}
\end{minipage}
\end{mdframed}
\RawCaption{\caption{General Caption.}
\label{fig:mwe}}
\end{figure}
\end{document}
And this is the result:
You can do so with the code as found at https://tex.stackexchange.com/a/245685/28093
\documentclass[margin=1cm]{standalone}
\usepackage{amsmath}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usetikzlibrary{calc}
%%% START MACRO FOR ANNOTATION OF TRIANGLE WITH SLOPE %%%.
\newcommand{\logLogSlopeTriangle}[5]
{
% #1. Relative offset in x direction.
% #2. Width in x direction, so xA-xB.
% #3. Relative offset in y direction.
% #4. Slope d(y)/d(log10(x)).
% #5. Plot options.
\pgfplotsextra
{
\pgfkeysgetvalue{/pgfplots/xmin}{\xmin}
\pgfkeysgetvalue{/pgfplots/xmax}{\xmax}
\pgfkeysgetvalue{/pgfplots/ymin}{\ymin}
\pgfkeysgetvalue{/pgfplots/ymax}{\ymax}
% Calculate auxilliary quantities, in relative sense.
\pgfmathsetmacro{\xArel}{#1}
\pgfmathsetmacro{\yArel}{#3}
\pgfmathsetmacro{\xBrel}{#1-#2}
\pgfmathsetmacro{\yBrel}{\yArel}
\pgfmathsetmacro{\xCrel}{\xArel}
%\pgfmathsetmacro{\yCrel}{ln(\yC/exp(\ymin))/ln(exp(\ymax)/exp(\ymin))} % REPLACE THIS EXPRESSION WITH AN EXPRESSION INDEPENDENT OF \yC TO PREVENT THE 'DIMENSION TOO LARGE' ERROR.
\pgfmathsetmacro{\lnxB}{\xmin*(1-(#1-#2))+\xmax*(#1-#2)} % in [xmin,xmax].
\pgfmathsetmacro{\lnxA}{\xmin*(1-#1)+\xmax*#1} % in [xmin,xmax].
\pgfmathsetmacro{\lnyA}{\ymin*(1-#3)+\ymax*#3} % in [ymin,ymax].
\pgfmathsetmacro{\lnyC}{\lnyA+#4*(\lnxA-\lnxB)}
\pgfmathsetmacro{\yCrel}{\lnyC-\ymin)/(\ymax-\ymin)} % THE IMPROVED EXPRESSION WITHOUT 'DIMENSION TOO LARGE' ERROR.
% Define coordinates for \draw. MIND THE 'rel axis cs' as opposed to the 'axis cs'.
\coordinate (A) at (rel axis cs:\xArel,\yArel);
\coordinate (B) at (rel axis cs:\xBrel,\yBrel);
\coordinate (C) at (rel axis cs:\xCrel,\yCrel);
% Draw slope triangle.
\draw[#5] (A)-- node[pos=0.5,anchor=north] {1}
(B)--
(C)-- node[pos=0.5,anchor=west] {#4}
cycle;
}
}
%%% END MACRO FOR ANNOTATION OF TRIANGLE WITH SLOPE %%%.
\begin{document}
\begin{tikzpicture}
\begin{loglogaxis}
[
xlabel=$x$,
ylabel style={rotate=-90},
ylabel=$y$,
legend style=
{
at={(1,1)},
anchor=north west,
draw=none,
fill=none
},
legend cell align=left,
grid=major,
clip=false
]
\addplot[blue,line width=1pt,domain=10^1:10^4] {sqrt(x)};
\addplot[red,line width=1pt,domain=10^1:10^4] {x};
\addplot[green!75!black,line width=1pt,domain=10^1:10^4] {x^2};
\addplot[brown,line width=1pt,domain=10^1:10^4] {x^3};
\logLogSlopeTriangle{0.9}{0.1}{0.16}{0.5}{blue};
\logLogSlopeTriangle{0.9}{0.1}{0.29}{1}{red};
\logLogSlopeTriangle{0.9}{0.1}{0.53}{2}{green!75!black};
\logLogSlopeTriangle{0.9}{0.1}{0.79}{3}{brown};
\legend
{
$\sqrt{x}$,
$x$,
$x^2$,
$x^3$
}
\end{loglogaxis}
\end{tikzpicture}
\end{document}
Result:
Best Answer