在 Tikz 图片中勾勒河流轮廓

在 Tikz 图片中勾勒河流轮廓

我想在 Tikz 图片中绘制的蓝色河流外部添加黑色边框,但问题是,由于我将其绘制为矩形组件,因此边框与河流内部相交。我该如何纠正这个问题?

\begin{minipage}{\textwidth}
\begin{figure}[H]
\centering
\begin{tikzpicture}
\definecolor{customgreen}{HTML}{a1fb7f}  
\definecolor{customblue}{HTML}{7b87ea}

% Draw the green land with a sharp border
\draw[fill=customgreen, draw=black, line width=0.5pt] (-7, -6) rectangle (7, 3);

% Then draw the blue rivers with a sharp blue border
% Extend bottom stream to the left
\draw[fill=customblue, draw=black] (-3, -2+.125) -- (-7,-2+.125) -- (-7,-1.125) -- (-3,-1.125) -- cycle;
% Extend the top stream to the right
\draw[fill=customblue, draw=black] (-3, 2) -- (7, 2) --(7, 2-.75) --(-3, 2-.75) -- cycle;
% Other parts of the river
\draw[fill=customblue, draw=black] (-3, 2) -- (-3+.75, 2) -- (-3+.75,-2+.125) -- (-3,-2+.125) -- cycle;
\draw[fill=customblue, draw=black] (3, 2-.75) -- (3-.75, 2-.75) --(3-.75, -5) --(3, -5) -- cycle;
\draw[fill=customblue, draw=black] (-3+.75, -1.125) -- (3-.75, -1.125) --(3-.75, -1.125-.75) --(-3+.75, -1.125-.75) -- cycle;
\draw[fill=customblue, draw=black] (3-.75, -5) -- (7, -5) --(7, -5+.75) --(3-.75, -5+.75) -- cycle;

% Nodes at landmasses
\node at (0, 0) {A};
\node at (5, -1.5) {B};
\node at (2.62500, 2.5) {C};
\node at (2.62500, -5.5) {D};

% Bridges with black borders
\filldraw[fill=brown, draw=black, line width=0.5pt] (-1.65, -1.125+.6) rectangle (-1.15, -1.875-.6); % Bridge 1
\filldraw[fill=brown, draw=black, line width=0.5pt] (-.25, -1.125+.6) rectangle (0.25, -1.875-.6); % Bridge 2
\filldraw[fill=brown, draw=black, line width=0.5pt] (-1.65, 2+.6) rectangle (-1.15, 1.25-.6); % Bridge 3
\filldraw[fill=brown, draw=black, line width=0.5pt] (-.25, 2+.6) rectangle (0.25, 1.25-.6); % Bridge 4
\filldraw[fill=brown, draw=black, line width=0.5pt] (2.25-.6, .25) rectangle (3+.6, -.25); % Bridge 5
\filldraw[fill=brown, draw=black, line width=0.5pt] (5-.25, 2+.6) rectangle (5.25, 1.25-.6); % Bridge 7
\filldraw[fill=brown, draw=black, line width=0.5pt] (5-.25, -5+.75+.6) rectangle (5.25, -5-.6); % Bridge 8
\end{tikzpicture}
\caption{Map of Königsberg. The blue represents the Pregel River while 
the green represents land. There are seven brown rectangles 
representing bridges connecting land masses.} \label{fig:figure1}
\end{figure}
\end{minipage}

输出:

在此处输入图片描述

答案1

您可以使用选项执行此double操作。只需使用一个\draw命令。您可以对桥梁执行相同的操作。使用line cap=butt将绘制颜色周围的完整边框,而不line cap=rect包括末端。但对接帽将超出坐标。

在此处输入图片描述

\documentclass{article}

\usepackage{tikz}
\definecolor{customgreen}{HTML}{a1fb7f}  
\definecolor{customblue}{HTML}{7b87ea}

\begin{document}

\begin{tikzpicture}
\draw[thick, fill=customgreen](0,-4)rectangle(11,4);
\draw[line cap=butt, thick, double=customblue, double distance=6mm]
    (0,0)--(7,0)
    (3,0)--(3,3)--(11,3)
    (7,3)--(7,-3)--(11,-3);
\draw[line cap=rect, thick, double=brown, double distance=4mm]
    (4,-.5)--(4,.5)
    (6,-.5)--(6,.5)
    (4,2.5)--(4,3.5)
    (6,2.5)--(6,3.5)
    (9,2.5)--(9,3.5)
    (9,-2.5)--(9,-3.5)
    (6.5,1.5)--(7.5,1.5);
\end{tikzpicture}

相关内容