1

How would it be possible to have the same space between the figure and both margins of the page in this example : enter image description here

Also, I would like to adjust the bottom side of the left figure with the axis x of the right tikzpicture : how to do so ?

Thank you for your help,

Best regards,

Code :

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{pgf, tikz, adjustbox}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{angles,calc}
\usetikzlibrary{spy}
\usetikzlibrary{patterns, matrix, positioning}
\usetikzlibrary{decorations.markings, decorations.pathreplacing, arrows.meta,
                patterns.meta,
                quotes}
\usetikzlibrary{shapes.geometric}
 %%HYPERBOLE   
    \newcommand\tikzhyperbola[6][thick]{%
    \draw [#1, rotate around={#2: (0, 0)}, shift=#3]
        plot [variable = \t, samples=1000, domain=-#6:#6] ({#4 / cos( \t )}, {#5 * tan( \t )});
        }

\begin{document}

\begin{figure}[h]
  \centering
  \begin{minipage}[t]{0.45\textwidth} % Définition de la taille de la première colonne
    \centering
    \includegraphics[width=\linewidth]{example-image}
    \caption*{Image 1}
    \vspace{1em} % Ajoutez de l'espace vertical si nécessaire
  \end{minipage} % Fin de la première colonne
  \hfill % Espace horizontal entre les deux colonnes
  \begin{minipage}[t]{0.5\textwidth} % Définition de la taille de la deuxième colonne
    \centering
    \begin{tikzpicture}[scale=0.45,
    the_angle/.style args = {#1/#2}{draw,latex-latex,
                                   angle radius=#1,
                                   angle eccentricity=#2,
                                   }, % angle label position
                                   ]
    
    \tikzset{
        elli/.style args={#1:#2and#3}{
            draw,
            shape=ellipse,
            rotate=#1,
            minimum width=2*#2,
            minimum height=2*#3,
            outer sep=0pt,
        }
    }
    \def\angle{90}
    \def\bigaxis{1.5cm}
    \def\smallaxis{1.5cm}
    \def\bigaxisbis{2.9cm}
    \def\smallaxisbis{3.6cm}
    
    \pgfmathsetmacro\axisratio{\smallaxis / \bigaxis}
    
    \coordinate (center) at (0, 0);
    
    \node [scale=0.55, elli=\angle:\bigaxis and \smallaxis, line width = 1.2pt, color=black, dotted] at (center) (e) {};
    
    \draw [-{stealth}, line width = 0.8pt, color = black] ([shift={(\angle:0)}] e.center) -- ([shift={(\angle:8)}] e.center) node [above right] {$z$};
    \draw [-{stealth}, line width = 1pt, color = black] ([shift={(0:-8)}] e.center) -- ([shift={(0:8)}] e.center) node [above left]  {$x$}  ;
    
    \draw[blue!80!black, very thick, Stealth-Stealth] (\bigaxis,0) --node[fill=white,scale = .65,right,xshift = 0.1 cm]{$h_{0}(t)$} (\bigaxis,\smallaxis);
    \draw[blue!80!black, dashed, thin] (0,\smallaxis) -- (\bigaxis,\smallaxis);
    \draw[red!80!black, very thick, Stealth-Stealth] (\bigaxisbis,0) --node[fill=white,scale = .65,right,xshift = 0.1 cm]{$h_{0}(t+\delta t)$} (\bigaxisbis,2.95cm);
    \draw[red!80!black, dashed, thin] (0,2.875cm) -- (3cm,2.95cm);
     % Dessin des 2 hyperboles
    \tikzhyperbola[line width = 1.2pt, color=blue!80!black]{\angle}{(center)}{\bigaxis}{\smallaxis}{77}
    \tikzhyperbola[line width = 1.2pt, color=red!80!black]{\angle}{(center)}{\bigaxisbis}{\smallaxisbis}{62}
    % asymptotes
    \def\lengthofasymptote{15}
            \coordinate (O) at (0,0); % intersection with coordinate axis
            \coordinate (C) at (-2,0);        
    % Dessin de l'arc de cercle entre CO et l'asymptote
    \draw[stealth-stealth, color=black, line width = 0.4pt]
        let \p1=($(O)-(C)$),\n1={veclen(\x1,\y1)} in
        (O) ++(135: \n1) arc (135:180: \n1) node[pos=0.5, above left] {$\alpha$};
    % asymptotes
    \draw [color=black!40, line width = 0.4pt, rotate around={45: (center)}]
        ($ (0, 0) + (center) $) --++(0.75*\lengthofasymptote, 0) ;
    \draw [color=black!40, line width = 0.4pt, rotate around={ 135: (center)}]
        ($ (0, 0) + (center) $) -- ++(0.75*\lengthofasymptote, 0) ;
    \end{tikzpicture}
    \caption*{Image 2}
    \vspace{1em} % Ajoutez de l'espace vertical si nécessaire
  \end{minipage} % Fin de la deuxième colonne
  \caption{Légende générale pour les deux figures}
  \label{fig:exemple_figures_alignees}
\end{figure}

\end{document}

EDIT : I tried implementing baseline to align the figures vertically but I committed a mistake because it's not working properly.

Code :

\begin{figure}[h]
  \centering
  \begin{minipage}[t]{0.4\textwidth} % Définition de la taille de la première colonne
    \centering
    \includegraphics[width=\linewidth]{example-image}
    \caption*{Image 1}
    \vspace{1em} % Ajoutez de l'espace vertical si nécessaire
  \end{minipage} % Fin de la première colonne
  \hfill % Espace horizontal entre les deux colonnes
  \begin{minipage}[t][\dimexpr\height+\depth\relax]{0.5\textwidth} % Définition de la taille de la deuxième colonne avec la même hauteur que l'image
    \centering
    \begin{tikzpicture}[baseline=(current bounding box.south),scale=0.45,
    the_angle/.style args = {#1/#2}{draw,latex-latex,
                                   angle radius=#1,
                                   angle eccentricity=#2,
                                   }, % angle label position
                                   ]  % BASELINE HERE
    \tikzset{
        elli/.style args={#1:#2and#3}{
            draw,
            shape=ellipse,
            rotate=#1,
            minimum width=2*#2,
            minimum height=2*#3,
            outer sep=0pt,
        }
    }
    \def\angle{90}
    \def\bigaxis{1.5cm}
    \def\smallaxis{1.5cm}
    \def\bigaxisbis{2.9cm}
    \def\smallaxisbis{3.6cm}
    
    \pgfmathsetmacro\axisratio{\smallaxis / \bigaxis}
    
    \coordinate (center) at (0, 0);
    
    \node [scale=0.55, elli=\angle:\bigaxis and \smallaxis, line width = 1.2pt, color=black, dotted] at (center) (e) {};
    
    \draw [-{stealth}, line width = 0.8pt, color = black] ([shift={(\angle:0)}] e.center) -- ([shift={(\angle:8)}] e.center) node [above right] {$z$};
    \draw [-{stealth}, line width = 1pt, color = black] ([shift={(0:-8)}] e.center) -- ([shift={(0:8)}] e.center) node [above left]  {$x$}  ;
    
    \draw[blue!80!black, very thick, Stealth-Stealth] (\bigaxis,0) --node[fill=white,scale = .65,right,xshift = 0.1 cm]{$h_{0}(t)$} (\bigaxis,\smallaxis);
    \draw[blue!80!black, dashed, thin] (0,\smallaxis) -- (\bigaxis,\smallaxis);
    \draw[red!80!black, very thick, Stealth-Stealth] (\bigaxisbis,0) --node[fill=white,scale = .65,right,xshift = 0.1 cm]{$h_{0}(t+\delta t)$} (\bigaxisbis,2.95cm);
    \draw[red!80!black, dashed, thin] (0,2.875cm) -- (3cm,2.95cm);
     % Dessin des 2 hyperboles
    \tikzhyperbola[line width = 1.2pt, color=blue!80!black]{\angle}{(center)}{\bigaxis}{\smallaxis}{77}
    \tikzhyperbola[line width = 1.2pt, color=red!80!black]{\angle}{(center)}{\bigaxisbis}{\smallaxisbis}{62}
    % asymptotes
    \def\lengthofasymptote{15}
            \coordinate (O) at (0,0); % intersection with coordinate axis
            \coordinate (C) at (-2,0);        
    % Dessin de l'arc de cercle entre CO et l'asymptote
    \draw[stealth-stealth, color=black, line width = 0.4pt]
        let \p1=($(O)-(C)$),\n1={veclen(\x1,\y1)} in
        (O) ++(135: \n1) arc (135:180: \n1) node[pos=0.5, above left] {$\alpha$};
    % asymptotes
    \draw [color=black!40, line width = 0.4pt, rotate around={45: (center)}]
        ($ (0, 0) + (center) $) --++(0.75*\lengthofasymptote, 0) ;
    \draw [color=black!40, line width = 0.4pt, rotate around={ 135: (center)}]
        ($ (0, 0) + (center) $) -- ++(0.75*\lengthofasymptote, 0) ;
    \end{tikzpicture}
    \caption*{Image 2}
    \vspace{1em} % Ajoutez de l'espace vertical si nécessaire
  \end{minipage} % Fin de la deuxième colonne
  \caption{Légende générale pour les deux figures}
  \label{fig:exemple_figures_alignees}
\end{figure}

Giving :

enter image description here

8
  • (1) I do not understand your first question. No idea what you are talking about. (2) As for your second and aligning the box with the x axis, put the figure into the tikzpicture. You know where the x axis is then you can also place something in ralation to it.
    – daleif
    Commented Apr 29 at 11:13
  • @daleif : You are right it was not explicit. I have edited the post with a better image : we can see that the left blank space of the figure is bigger than the right one.
    – Waxler
    Commented Apr 29 at 11:19
  • 1
    Your graph is too wide to fit in the minipage. The margins will be the same if you scale your image to be the same width as the minipage. Commented Apr 29 at 11:30
  • 1
    For the vertical alignment, have a look at the baseline option in the tikz user manual Commented Apr 29 at 12:46
  • 1
    @Waxler Try something like baseline=0cm. You don't want to align the baseline with the South edge of the image as your dotted circle is lower than your x axis. Commented Apr 29 at 15:02

1 Answer 1

2

Your drawing on the right is wider than the allotted space.

If I add, for the purpose of showing the bounding boxes,

\usepackage[pass,showframe]{geometry}
\setlength{\fboxsep}{-\fboxrule}

to the document preamble and enclose the two minipages inside \fbox{...}, I get

enter image description here

You see that the drawing goes off the minipage and you're even warned about this:

Overfull \hbox (33.35834pt too wide) in paragraph at lines 91--91

(line numbers might differ).

Of course, this depends on the text width you have in your document. With the standard text width, if you need the proportion 0.45 : 0.5, you need to scale down one or both parts.

Scaling down the drawing to 0.35, rather than 0.45 as you have in the code, seems quite satisfactory:

enter image description here

I used \begin{minipage}[b] for both, rather than [t], so the two legends are well aligned. No need for \caption*, by the way.

\documentclass{article}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{pgfplots}
\usepackage{pgf, tikz, adjustbox}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{angles,calc}
\usetikzlibrary{spy}
\usetikzlibrary{patterns, matrix, positioning}
\usetikzlibrary{decorations.markings, decorations.pathreplacing, arrows.meta,
                patterns.meta,
                quotes}
\usetikzlibrary{shapes.geometric}

 %%HYPERBOLE   
\newcommand\tikzhyperbola[6][thick]{%
  \draw [#1, rotate around={#2: (0, 0)}, shift=#3]
    plot [variable = \t, samples=1000, domain=-#6:#6] ({#4 / cos( \t )}, {#5 * tan( \t )});
}

\begin{document}

\begin{figure}[htp]
  \centering
  \begin{minipage}[b]{0.45\textwidth} % Définition de la taille de la première colonne
    \centering
    \includegraphics[width=\linewidth]{example-image}
    \caption*{Image 1}
  \end{minipage}% Fin de la première colonne
  \hfill % Espace horizontal entre les deux colonnes
  \begin{minipage}[b]{0.5\textwidth} % Définition de la taille de la deuxième colonne
    \centering
    \begin{tikzpicture}[
      scale=0.35,% <--- CHANGED HERE
      the_angle/.style args = {#1/#2}{
        draw,
        latex-latex,
        angle radius=#1,
        angle eccentricity=#2,
      }, % angle label position
      elli/.style args={#1:#2and#3}{
        draw,
        shape=ellipse,
        rotate=#1,
        minimum width=2*#2,
        minimum height=2*#3,
        outer sep=0pt,
      },
    ]
    \def\angle{90}
    \def\bigaxis{1.5cm}
    \def\smallaxis{1.5cm}
    \def\bigaxisbis{2.9cm}
    \def\smallaxisbis{3.6cm}
    
    \pgfmathsetmacro\axisratio{\smallaxis / \bigaxis}
    
    \coordinate (center) at (0, 0);
    
    \node [scale=0.55, elli=\angle:\bigaxis and \smallaxis, line width = 1.2pt, color=black, dotted] at (center) (e) {};
    
    \draw [-{stealth}, line width = 0.8pt, color = black] ([shift={(\angle:0)}] e.center) -- ([shift={(\angle:8)}] e.center) node [above right] {$z$};
    \draw [-{stealth}, line width = 1pt, color = black] ([shift={(0:-8)}] e.center) -- ([shift={(0:8)}] e.center) node [above left]  {$x$}  ;
    
    \draw[blue!80!black, very thick, Stealth-Stealth] (\bigaxis,0) --node[fill=white,scale = .65,right,xshift = 0.1 cm]{$h_{0}(t)$} (\bigaxis,\smallaxis);
    \draw[blue!80!black, dashed, thin] (0,\smallaxis) -- (\bigaxis,\smallaxis);
    \draw[red!80!black, very thick, Stealth-Stealth] (\bigaxisbis,0) --node[fill=white,scale = .65,right,xshift = 0.1 cm]{$h_{0}(t+\delta t)$} (\bigaxisbis,2.95cm);
    \draw[red!80!black, dashed, thin] (0,2.875cm) -- (3cm,2.95cm);
     % Dessin des 2 hyperboles
    \tikzhyperbola[line width = 1.2pt, color=blue!80!black]{\angle}{(center)}{\bigaxis}{\smallaxis}{77}
    \tikzhyperbola[line width = 1.2pt, color=red!80!black]{\angle}{(center)}{\bigaxisbis}{\smallaxisbis}{62}
    % asymptotes
    \def\lengthofasymptote{15}
            \coordinate (O) at (0,0); % intersection with coordinate axis
            \coordinate (C) at (-2,0);        
    % Dessin de l'arc de cercle entre CO et l'asymptote
    \draw[stealth-stealth, color=black, line width = 0.4pt]
        let \p1=($(O)-(C)$),\n1={veclen(\x1,\y1)} in
        (O) ++(135: \n1) arc (135:180: \n1) node[pos=0.5, above left] {$\alpha$};
    % asymptotes
    \draw [color=black!40, line width = 0.4pt, rotate around={45: (center)}]
        ($ (0, 0) + (center) $) --++(0.75*\lengthofasymptote, 0) ;
    \draw [color=black!40, line width = 0.4pt, rotate around={ 135: (center)}]
        ($ (0, 0) + (center) $) -- ++(0.75*\lengthofasymptote, 0) ;
    \end{tikzpicture}
    \caption*{Image 2}
  \end{minipage} % Fin de la deuxième colonne

\caption{Légende générale pour les deux figures}
\label{fig:exemple_figures_alignees}

\end{figure}

\end{document}

enter image description here

Raising the image doesn't seem right, in this case, but it depends on the proportions of your actual picture.

Gauge it by eye. With

  \begin{minipage}[b]{0.45\textwidth} % Définition de la taille de la première colonne
    \centering
    \includegraphics[width=\linewidth]{example-image}

    \vspace{5ex}

    \caption*{Image 1}
  \end{minipage}% Fin de la première colonne

for the picture, the output is

enter image description here

1
  • Thank you very much for your help : I've also used the scaling option to adjust the figure correctly after the remarks in my original post's comments (I wanted to avoid reshaping my figure just for this particular minipage). For the vertical alignement, I used baselinebut for some reason baseline = 0 cmdidn't work for my original image : I had to put baseline =-3cmbut I don't understand the meaning of such a value. I have to admit that I still don't understand the way coordinates and adjustments are made in latex, I struggle regularly with that. thank you again for your answer !
    – Waxler
    Commented Apr 30 at 8:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .