如何完善线路连接?

如何完善线路连接?

我想完善我的行连接。我该如何实现?我尝试line join=round\begin{tikzpicture}环境中这样做\begin{tikzpicture}[line join=round],但并没有解决问题。

右上 在此处输入图片描述

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
%\usepackage[graphics, active, tightpage]{preview}
%\PreviewEnvironment{tikzpicture}

%!tikz preamble begin
\usetikzlibrary{shapes.geometric, arrows.meta, 3d, calc}
\usepackage{tikz-3dplot}

\usetikzlibrary{decorations.markings}

\usetikzlibrary{shapes,positioning, backgrounds, scopes}

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground} 
%!tikz preamble end

\begin{document}
\begin{tikzpicture}[>=latex,line join=round,scale=1.5]

\pgfmathsetmacro{\cubex}{5}
\pgfmathsetmacro{\cubey}{1}
\pgfmathsetmacro{\cubez}{5}
\newcommand{\boxcolor}{yellow!20!}
\begin{pgfonlayer}{foreground}
    \draw[red!20!] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
    \draw[red!20!] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
    \draw[red!20!] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\end{pgfonlayer}
\begin{pgfonlayer}{background}
    \draw[fill=\boxcolor] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
    \draw[fill=\boxcolor] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
    \draw[fill=\boxcolor] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\end{pgfonlayer}

\end{tikzpicture}
\end{document}

谢谢!

答案1

另一个版本没有,\clip但也是将pgfonlayers 替换为scopes。请注意,\draw[fill=\boxcolor]被替换为\fill[\boxcolor]。使用\draw[fill=\boxcolor,line cap=round, line join =round]也可以正常工作。

\documentclass[tikz,border=1cm]{standalone}
\usetikzlibrary{backgrounds}

\begin{document}
\begin{tikzpicture}[>=latex,scale=1.5,line cap=round, line join =round]
\pgfmathsetmacro{\cubex}{5}
\pgfmathsetmacro{\cubey}{1}
\pgfmathsetmacro{\cubez}{5}
\newcommand{\boxcolor}{yellow!20!}
\begin{scope}
    \node at (-0.5*\cubex,-0.5*\cubey,-0.25*\cubez) {\Huge some text};
    \draw[red!20!] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
    \draw[red!20!] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
    \draw[red!20!] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;

\end{scope}
\begin{scope}[on background layer={line cap=round, line join =round}]
    \fill[\boxcolor] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
    \fill[\boxcolor] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
    \fill[\boxcolor] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\end{scope}

\end{tikzpicture}
\end{document}

编辑回顾pgf-tikz手动的,§45与backgrounds库相关,解释了传递给的选项允许on background layer将选项传递给 内部的所有对象scope,从而彻底解决了该问题。

在此处输入图片描述

答案2

您可以使用 clip 仅沿边缘绘制内侧一半的线条。当然,clip 内部的线条宽度将是其两倍。

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
%\usepackage[graphics, active, tightpage]{preview}
%\PreviewEnvironment{tikzpicture}

%!tikz preamble begin
\usetikzlibrary{shapes.geometric, arrows.meta, 3d, calc}
\usepackage{tikz-3dplot}

\usetikzlibrary{decorations.markings}

\usetikzlibrary{shapes,positioning, backgrounds, scopes}

\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground} 
%!tikz preamble end

\begin{document}
\begin{tikzpicture}[>=latex,line join=round,scale=1.5]

\pgfmathsetmacro{\cubex}{5}
\pgfmathsetmacro{\cubey}{1}
\pgfmathsetmacro{\cubez}{5}
\newcommand{\boxcolor}{yellow!20!}

\begin{pgfonlayer}{foreground}
  \clip (-\cubex,0,-\cubez) -- (0,0,-\cubez) -- (0,-\cubey,-\cubez) -- (0,-\cubey,0)
    -- (-\cubex,-\cubey,0)-- (-\cubex,0,0) -- cycle;
    \draw[red!20!] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
    \draw[red!20!] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
    \draw[red!20!] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\end{pgfonlayer}
\begin{pgfonlayer}{background}
  \clip (-\cubex,0,-\cubez) -- (0,0,-\cubez) -- (0,-\cubey,-\cubez) -- (0,-\cubey,0)
    -- (-\cubex,-\cubey,0)-- (-\cubex,0,0) -- cycle;
    \draw[fill=\boxcolor] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,-\cubey,0) -- ++(\cubex,0,0) -- cycle;
    \draw[fill=\boxcolor] (0,0,0) -- ++(0,0,-\cubez) -- ++(0,-\cubey,0) -- ++(0,0,\cubez) -- cycle;
    \draw[fill=\boxcolor] (0,0,0) -- ++(-\cubex,0,0) -- ++(0,0,-\cubez) -- ++(\cubex,0,0) -- cycle;
\end{pgfonlayer}

\end{tikzpicture}
\end{document}

相关内容