如何使这个物体看起来像一个漂亮的长方体?

如何使这个物体看起来像一个漂亮的长方体?

我写了一段代码来得到一个漂亮的长方体,但它看起来有点扭曲。如果有人能为输出注入美感,我会很高兴。

(如果问题过于局部,我很抱歉;如果您认为如此,请随意(投票)关闭。)

\documentclass{amsart}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{tikz}
\usetikzlibrary{matrix,arrows}
\newcommand{\Z}{\mathbb Z}
\begin{document}
\begin{tikzpicture}
 \matrix (m) [matrix of math nodes, row sep=0.5em,
              column sep=2em]{
      &\Z/30\Z& \\
\Z/15\Z&&\\
       &\Z/10\Z& \\
       &&\Z/6\Z \\
\Z/5\Z&& \\
      &\Z/3\Z& \\
      &&\Z/2\Z \\
      &\{1\}& \\};
 \path[-]
    (m-1-2) edge (m-2-1) 
    edge (m-3-2)
    edge (m-4-3)
    (m-3-2) edge (m-5-1)
    (m-2-1) edge [-,line width=6pt,draw=white](m-6-2)
    edge (m-6-2)
    (m-2-1) edge (m-5-1)
    (m-8-2) edge (m-5-1)
    edge (m-6-2)
    edge (m-7-3)
    (m-7-3) edge (m-4-3)
    (m-3-2) edge (m-7-3)
    (m-4-3) edge [-,line width=6pt,draw=white](m-6-2)
    edge (m-6-2);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

人们经常忽略,虽然 TikZ 无法制作“真正的”三维图形,但它确实有一个 xyz 坐标系,这对于绘制立方体非常有用。只需调整坐标单位选项即可根据自己的喜好调整视图。

\documentclass[11pt]{article}
\usepackage{tikz}
\usepackage{amsmath}
\usepackage{amssymb}
\newcommand{\Z}{\mathbb Z}

\begin{document}

\begin{tikzpicture}[
        x={(4em,4em)},
        y={(-6em,8em)},
        z={(0,5em)}]
    \node (b1) at (0,0,0) {$\{1\}$};
    \node (b2) at (1,0,0) {$\Z/2\Z$};
    \node (b3) at (1,1,0) {$\Z/10\Z$};
    \node (b4) at (0,1,0) {$\Z/5\Z$};
    \node (t1) at (0,0,1) {$\Z/3\Z$};
    \node (t2) at (1,0,1) {$\Z/6\Z$};
    \node (t3) at (1,1,1) {$\Z/30\Z$};
    \node (t4) at (0,1,1) {$\Z/15\Z$};

    \draw (b1) -- (b2) -- (b3) -- (b4) -- (b1);
    \draw[preaction={draw,white,line width=5pt}] (t1) -- (t2) -- (t3) -- (t4) -- (t1);
    \foreach \x in {1,...,4} {
        \draw (b\x) -- (t\x);
    }
\end{tikzpicture}
\end{document}

结果

答案2

您需要向空单元格添加节点以获得正确的间距。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\begin{document}
\def\Z{Z}
\begin{tikzpicture}
 \matrix (m) [execute at empty cell={\node{\phantom{\Z}};},
    matrix of math nodes, nodes={inner xsep=0pt},row sep=0.5em,
              column sep=3em]{
        &   \Z/30\Z & \\
        &           & \\
\Z/15\Z &           &\\
        &\Z/10\Z    & \\
        &           &\Z/6\Z \\
\Z/5\Z  &           & \\
        &\Z/3\Z     & \\
        &           &\Z/2\Z \\
        &           & \\
        &\{1\}      & \\};
 \path[-]
    (m-1-2) edge (m-3-1) 
    edge (m-4-2)
    edge (m-5-3)
    (m-4-2) edge (m-6-1)
    (m-3-1) edge [-,line width=6pt,draw=white](m-7-2)
    edge (m-7-2)
    (m-3-1) edge (m-6-1)
    (m-10-2) edge (m-6-1)
    edge (m-7-2)
    edge (m-8-3)
    (m-8-3) edge (m-5-3)
    (m-4-2) edge (m-8-3)
    (m-5-3) edge [-,line width=6pt,draw=white](m-7-2)
    edge (m-7-2);
\end{tikzpicture}

\end{document}

答案3

为了获得稍微手动但仍然易于维护的代码,您可以定义下部和上部矩形并在周围放置节点。复制/粘贴使处理代码变得更容易。当然总有需要改进的地方。

\documentclass[11pt]{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage{amsmath}
\usepackage{amssymb}
\newcommand{\Z}{\mathbb Z}
\begin{document}

\begin{tikzpicture}[every node/.style={fill=white}]
%This is to be copied in a scope for the upper layer
\coordinate (b) at (3,2);
\coordinate (c) at (-3,3);
\draw (0,0) -- ++(b) -- ++(c) --++($-1*(b)$)--cycle;
\node (n1) at (0,0)                    {$\{1\}$};
\node (n2) at (b)                      {$\Z/2\Z$};
\node (n3) at ($(b)+(c)$)              {$\Z/10\Z$};
\node (n4) at ($(n3)-(b)$)             {$\Z/5\Z$};
%until here

\begin{scope}[yshift=2cm]
\coordinate (b) at (3,2);
\coordinate (c) at (-3,3);
\draw[preaction={draw,white,line width=5pt}] (0,0) -- ++(b) -- ++(c) -- ++($-1*(b)$)--cycle;
\node (n5) at (0,0)                    {$\Z/3\Z$};
\node (n6) at (b)                      {$\Z/6\Z$};
\node (n7) at ($(b)+(c)$)              {$\Z/30\Z$};
\node (n8) at ($(n7)-(b)$)             {$\Z/15\Z$};
\end{scope}
%The verticals
\foreach \x [count=\xi from 5] in {1,...,4} {
\draw (n\x) -- (n\xi);
}

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案4

使用 运行它latex->dvips->ps2pdf。您可以更改视点 (xyz) 以获得不同的视图。

\documentclass{article}
\usepackage{amssymb}
\usepackage{pst-gr3d}
\newcommand\Z{\mathbb{Z}}
\begin{document}

\PstGridThreeD[unit=4cm,viewpoint=0.4 -0.4 0.6,GridThreeDNodes,
  PstPicture=](1,1,1)
\rput*(Gr3dNode111){$\Z/6\Z$}
\rput*(Gr3dNode011){$\Z/30\Z$}
\rput*(Gr3dNode001){$\Z/15\Z$}
\rput*(Gr3dNode101){$\Z/3\Z$}
\rput*(Gr3dNode110){$\Z/2\Z$}
\rput*(Gr3dNode100){$\{1\}$}
\rput*(Gr3dNode010){$\Z/10\Z$}
\rput*(Gr3dNode000){$\Z/5\Z$}

\end{document}

在此处输入图片描述

相关内容