TransWikia.com

How to draw a vertical line between two tikzpictures

TeX - LaTeX Asked on October 1, 2021

I am drawing two tikzpictures side by side as follows:

documentclass[standalone]{beamer}
usepackage{tikz}
usetikzlibrary{arrows.meta, shadows}
usepackage{default}
begin{document}
begin{frame}
    begin{center}
    begin{tikzpicture}[scale=0.6]
    node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (1) at (2.5,-1.5) {1};
    node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (2) at (1,-3) {2};
    path (1) edge [->] node {} (2);
    end{tikzpicture}
    hspace{1cm}
    vspace{-1cm}
    begin{tikzpicture}[scale=0.6]
    node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (2) at (2,1) {1};
    node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (1) at (0.5, -0.5) {2};
    path (1) edge [->] node {} (2);
    end{tikzpicture}
end{center}
end{frame}
end{document}

How can I draw a vertical black line the full height between the two?

2 Answers

I build everything in one tikzpicture environment. The two diagrams being identical (except for the direction of the arrow), I simply put each diagram in a scope environment by giving them the name of fig 1 and fig 2. The second one is shifted to the right.

begin{scope}[local bounding box=fig 1]
begin{scope}[xshift=5cm,local bounding box=fig 2]

To draw a line right in between, I calculate the line that passes right in between.

draw ($(fig 1.north east)!.5!(fig 2.north west)$) --($(fig 1.south east)!.5!(fig 2.south west)$);

screenshot

documentclass[standalone]{beamer}
usepackage{tikz}
usetikzlibrary{arrows.meta, shadows,calc}
%usepackage{default}
begin{document}
begin{frame}
    begin{center}
    begin{tikzpicture}[scale=0.6]
    begin{scope}[local bounding box=fig 1]
        node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (1) at (2.5,-1.5) {1};
    node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (2) at (1,-3) {2};
    path (1) edge [->] node {} (2);
    end{scope}

%    end{tikzpicture}
%    hspace{1cm}
%    vspace{-1cm}
%    begin{tikzpicture}[scale=0.6]

    begin{scope}[xshift=5cm,local bounding box=fig 2]
        node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (1) at (2.5,-1.5) {1};
    node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (2) at (1,-3) {2};
    path (1) edge [<-] node {} (2);
    end{scope}

draw ($(fig 1.north east)!.5!(fig 2.north west)$) --($(fig 1.south east)!.5!(fig 2.south west)$);

    end{tikzpicture}
end{center}
end{frame}
end{document}

Correct answer by AndréC on October 1, 2021

You can insert the two tikz pictures inside a tabular:

documentclass[standalone]{beamer}
usepackage{tikz}
usetikzlibrary{arrows.meta, shadows}
%usepackage{default}

begin{document}
begin{frame}
    begin{center}
    begin{tabular}{c@{quad}|@{quad}c}
    begin{tikzpicture}[scale=0.6]
    node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (1) at (2.5,-1.5) {1};
    node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (2) at (1,-3) {2};
    path (1) edge [->] node {} (2);
    end{tikzpicture}
    &
    begin{tikzpicture}[scale=0.6]
    node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (2) at (2,1) {1};
    node[shape=circle,draw=black,fill=white, drop shadow,minimum size=1cm] (1) at (0.5, -0.5) {2};
    path (1) edge [->] node {} (2);
    end{tikzpicture}    
    end{tabular}
end{center}
end{frame}
end{document}

enter image description here

Answered by AboAmmar on October 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP