Sagittarius Rover
Sagittarius Rover
这家伙很懒,什么也没写!

注册于 3年前

回答
525
文章
0
关注者
21

@u444 代码要尽量给完整,不要只给一个片段,同时要放在代码块内。

注意到原图其实是想表达3D的角度,原图的展示不符合实际情况,你在评论区中给出的图又完全是2D的,也似乎不完全符合实际情况。

以下是基于luadraw的一个可能方案,可以解决「但是代码不够好看以及视角不够灵活等缺点」,需要自行安装并用lualatex编译:

\documentclass{standalone}
\usepackage[3d]{luadraw}
\usepackage[svgnames]{xcolor}
\usepackage{fourier}
\begin{document}
\begin{luadraw}{name=axis_vector}
local g = graph3d:new{ 
    window3d={-1,9,-1,9,-1,9}, 
    window = {-6,8,-5,8},size={12,12},
    viewdir=perspective("xy",0.8,60), 
    pictureoptions="every node/.append style={scale=1.5}"
}
local O,delta,P = Origin,-3, M(6.5, 6, 4)
local Pxz = pxz(P)
local Px,Pz,Py = px(Pxz), pz(Pxz), py(P)
local t1, t2, t3 = M(delta, 0, P.z), M(delta,0, 0), M(delta, P.y, 0)

g:Dpolyline3d({{O, 7*vecI}, {O, 7*vecJ}, {O, 7*vecK}}, "-Stealth,solid,black, line width=1pt")
g:Dlabel3d(
    "$x$", 7*vecI, {pos="N",dist=0.1}, 
    "$y$", 7*vecJ, {pos="W"}, 
    "$z$", 7*vecK, {pos="E"}
    )

g:Dpolyline3d({{P,Py}, {P,Pxz}, {Pxz,Px}, {Pxz,t1},{O,Pxz}}, "dashed,blue,thick")
g:Dpolyline3d({{O,t2}, {Py,t3}}, "dashed,black,thick")

g:Dpolyline3d({{t1,t2}, {t2,t3}, {Pxz,Pz}}, "Stealth-Stealth,dashed,magenta,thick")
g:Dlabel3d(
    "$z$", (t1+t2)/2, {pos="NW",node_options="text=magenta"},
    "$y$", (t2+t3)/2, {pos="W"},
    "$x$", (Pxz+Pz)/2, {pos="S"}
)

g:Dseg3d({O, P}, "-latex,PaleVioletRed,line width=4pt")
g:Dpolyline3d({{O, 2.5*vecI}, {O, 2.5*vecJ}, {O, 2.5*vecK}}, "-latex,cyan,line width=3pt")
g:Dlabel3d("$\\vec{i}$", 2.5*vecI, {pos="S",node_options="text=cyan"}, "$\\vec{j}$", 2.5*vecJ, {pos="W"}, "$\\vec{k}$", 2.5*vecK, {})

g:Ddots3d({P}, "PaleVioletRed,scale=4", 1.5)
g:Dlabel3d("$P$", P, {pos="NE"},"$\\vec{r}$", P, {pos="W",dist=0.35,node_options="text=PaleVioletRed"})

for _,i in ipairs({Px, Py, Pz}) do
    g:Ddots3d({i}, "blue", 1.5)
end

local configs = {
    {pt=Px, col="blue"},
    {pt=Py, col="green"},
    {pt=Pz, col="violet"}
}
for _, item in ipairs(configs) do
    g:Dpath3d({item.pt, O, P, 3.75, 1, "ca", O, "l"}, "draw=none,opacity=0.2,fill=" .. item.col)
    g:Darc3d(item.pt, O, P, 3.75, 1, "-Stealth,thick," .. item.col .. ",ultra thick")
end

g:Dlabel(
    "$\\alpha$",Z(3.25,1), {node_options="text=blue"},
    "$\\beta$", Z(1.5,3), {node_options="text=green"},
    "$\\gamma$", Z(0.5,-1.2), {node_options="text=violet"}
)

g:Show()

\end{luadraw}
\end{document}

image.png

Here below is the proposal of luadraw:

Some details need to be tweaked by yrself.

% https://ask.latexstudio.net/ask/question/8020.html
\documentclass{standalone}
\usepackage[fontset=fandol]{ctex}
\usepackage[3d]{luadraw}
\usepackage[svgnames]{xcolor}
\usepackage{fourier}
\begin{document}

    \begin{luadraw}{name=earth_tilted_system}
        local g = graph3d:new{
            window3d={-8,8,-8,8,-6,6}, 
            window = {-8,9,-6,6},
            size={10,10}, viewdir={0,80},
            pictureoptions = "line cap=round"
        }
        -- first half plane
        g:Dpath3d(
            {M(0,-7,0),M(-8,-6,0), M(-8,8,0), M(0,7,0),"l", 4*vecJ, "m", Origin, -4*vecJ, 4, 1, vecK, "ca"},
            "fill=yellow!15, fill opacity=1, draw=orange, line width=0.5pt"
        )
        g:Darc3d(4*vecJ, Origin, -4*vecJ, 4, 1, vecK, "teal, line width=0.5pt") -- inner edge
        -- Rotate3d alter the transfoemmation matrix
        g:Saveattr()
            g:Rotate3d(-23.26, {Origin, vecI})
            g:Dcircle3d(Origin, 4, vecK, "fill=yellow, draw=orange, line width=0.5pt")
            g:Dsphere(Origin, 4, {mode=mBorder, edgecolor="cyan", edgewidth=10})
        g:Restoreattr()
        -- second half plane
        g:Dpath3d(
            {M(0,-7,0),M(8,-8,0), M(8,6,0), M(0,7,0),"l", 4*vecJ, "m", Origin, -4*vecJ, 4, -1, vecK, "ca"},
            "fill=yellow!15, fill opacity=1, draw=orange, line width=0.5pt"
        )
        g:Darc3d(4*vecJ, Origin, -4*vecJ, 4, -1, vecK, "teal, line width=0.5pt") -- outer edge
        -- hidden lines
        g:Dcircle3d(Origin, 4, g.Normal, "dashed,cyan,line width=0.8pt")
        g:Dcircle3d(Origin, 4, vecK, "dashed,teal")
        -- Rotate3d alter the transfoemmation matrix again
        g:Saveattr()
        g:Rotate3d(-23.26, {Origin, vecI})
        -- hidden ellipse
        -- g:Dcircle3d(Origin, 4, vecK, "orange,dashed")
        -- the z-axis
        g:Dline3d({-1.5 * vecK, 1.5 * vecK}, "black, dashed, line width=0.8pt")
        -- the rotated y-axis
        g:Dseg3d({Origin, 8 * vecJ}, "teal, dashed, line width=0.8pt")
        g:Dlabel3d(
            "赤道平面", M(0.5,-2,0), {dir={vecJ,M(-8,1,0)},node_options="scale=0.75"}
        )
        g:Restoreattr()
        -- magenta segments 
        g:Dseg3d({Origin, 4 * vecJ}, "magenta, dashed, line width=0.8pt")
        g:Dseg3d({8*vecJ, 4 * vecJ}, "magenta, line width=0.8pt")
        -- arc3d
        g:Darc3d(5 * vecJ, Origin, Ms(4,90*deg,23.26*deg),5,1, "red,latex-latex") -- 90*deg = pi/2 (radians)
        g:Darc3d(8*vecJ, Origin, Ms(4,90*deg,(90+23.26)*deg),8,1, "red,latex-latex")
        g:Dlabel3d(
            "黄道平面", M(5,-6,0), {dir={vecJ,M(-8,1,0)},node_options="scale=0.75"},
            "$66^\\circ 34'$", Ms(5,90*deg,(45+23.26/2)*deg), {
                node_options="fill=white,inner sep=1.5pt", 
                dir={Ms(1,90*deg,(135+23.26/2)*deg), Ms(1,90*deg,(45+23.26/2)*deg)}
            },
            "$23^\\circ 26'$", Ms(8,90*deg,(90+23.26/2)*deg), 
            {node_options="fill=white,inner sep=1.5pt", dir={Ms(1,90*deg,(180+23.26/2)*deg), Ms(1,90*deg,(90+23.26/2)*deg)}}
        )
        g:Dlabel(
            "黄\\\\赤\\\\交\\\\角", Z(8.75,-1.75,0), {node_options="scale=0.8,text=red,align=left,font=\\bfseries\\linespread{1}\\selectfont"}
        )
        g:Show()
    \end{luadraw}
\end{document}

image.png

hspan=minimal is all I need, actually...

对文档还是不够熟悉(摇头...)

image.png

\documentclass[12pt]{article}
\usepackage[fontset=fandol]{ctex}
\usepackage[showframe,a4paper,hmargin=1.25cm]{geometry}
\usepackage{tabularray}
\UseTblrLibrary{booktabs,varwidth}
\setlength{\parindent}{0pt}
\usepackage{lipsum}
\begin{document}

\begin{tblr}{
    colspec={X[1.25,c,m]X[1.75,c,m]X[1,c,m]X[1.5,c,m]X[1.75,c,m]},
    hlines,vlines,
    hline{1,Z} = {2pt},
    vline{1,Z} = {2pt},
    width=\linewidth,
    measure=vbox,
    hspan=minimal,
    rows = {ht=1cm},
    row{3} = {ht=2.5cm},
    row{X-Y} = {ht=3cm},
    cell{1}{1-Y} = {r=2}{valign=m},
    cell{2}{Z} = {r=3}{valign=m},
    cell{3}{2} = {c=3}{valign=m},
    cell{5-Z}{2} = {c=4}{halign=l,valign=m},
    cell{X-Y}{2} = {valign=h},
}
课程名称 & & {学\quad 分} & & {总计:\qquad 学时} \\
& & & & {\linespread{1.75}\selectfont 讲课:\qquad 学时\\讲课:\qquad 学时\\讲课:\qquad 学时\\讲课:\qquad 学时\\讲课:\qquad 学时\\} \\
{课程性质\\[10pt](请打勾)} & %
{\linespread{1.5}\selectfont%<- important % hete
    通识必修课(\quad)\ 通识选修课(\quad)\ 专业必修课(\quad)\\
    通识必修课(\quad)\ 通识选修课(\quad)\ 专业必修课(\quad)\\
    通识必修课(\quad)\ 通识选修课(\quad)\ 专业必修课(\quad)\\
}  
&  &  &  \\
任课老师 &  & 职称 &  &  \\
授课对象 & 年级、专业: &  &  &  \\
课程目标 &  &  &  &  \\
教学重难点 &  &  &  &  \\
% 教材 & {教材:} &  &  &  \\
% 参考资料 & {参考资料:} &  &  &  \\
教材 & {教材:\lipsum[2][1-6]} &  &  &  \\
参考资料 & {参考资料:\lipsum[2][1-6]} &  &  &  \\
其他要求 &  &  &  &  \\
\end{tblr}

\bigskip

Notes: \lipsum[2][1-5]

\end{document}

image.png

使用需要lualatextkz-elements包(v5.13c)在处理椭圆切线等问题会方便很多:

\documentclass[border=5pt]{standalone}
\usepackage[mini]{tkz-euclide}
\usepackage{tkz-elements}
\directlua{
    init_elements()
    z.O = point(0.15, 0.6) 
    C.OW = circle(through(z.O, 0.5))
    z.W = C.OW.through
    z.M = point(-0.25, -1)
    z.N = point(1,4)
    z.C = tkz.midpoint(z.M, z.N)
    L.MN = line(z.M, z.N)
    z.T = L.MN:orthogonal_at(z.C, {length = 1.5})
    CO.EL = conic(EL_points(z.C, z.N, z.T))
    PA.curve = CO.EL:points(0, 1, 100)
    z.P = point(4,-1)
    L.tan, _ = CO.EL:tangent_from(z.P)
    z.Q = L.tan.pb
    L.normal = L.tan:ortho_from(z.Q)
    z.dir = L.normal:report(-1.5, z.Q)
    z.H = line(z.P, z.Q):projection(z.O)
    z.v, _ = intersection(line(z.O,z.Q), C.OW)
    z.u, _ = intersection(line(z.O,z.H), C.OW)
}
\begin{document}

\begin{tikzpicture}
    \tkzGetNodes
    \tkzDrawCoordinates[smooth,thick](PA.curve)  \tkzDrawCircle[black,thick](O,W)
    \tkzDrawSegments[thick,-latex](Q,dir)
    \tkzDrawSegments[thick,add=0 and 0.5](P,Q)
    \tkzDrawSegments[thick,dashed,green](O,Q)
    \tkzDrawSegments[thick,green,-latex](O,v)
    \tkzDrawSegments[thick,dash dot,blue](O,H)
    \tkzDrawSegments[thick,blue,-latex](O,u)
    \tkzMarkRightAngle[size=.25,thick](O,H,Q)
    \tkzMarkRightAngle[size=.25,thick](P,Q,dir)
    \draw [magenta,decorate,decoration={brace,mirror,amplitude=10pt}] (O) -- (H) node[midway,below right,xshift=-.15cm,yshift=-.25cm,black] {$h(K,u)$};
    % labels left is your time~
\end{tikzpicture}

\end{document}

image.png

其实还可以使用cascade宏包,不过他没有那么多的微调功能 :-(

由于懒,这里只贴文档的图。

image.png

declare function看文档似乎只能允许一元的输出...

如果重复使用这个坐标就要写很多次了,虽然可以复制粘贴,但是不太优雅
image.png

我一般的做法是\pgfmathsetmacro:

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \ii in {0, 1, ..., 5}{
  \foreach \jj in {0, 1, ..., 4}{
    \pgfmathsetmacro{\x}{\ii+\jj*0.5}
    \pgfmathsetmacro{\y}{-\jj*0.8}
    \node at (\x,\y) {$(\ii,\jj)$};
  }
}
\end{tikzpicture}
\end{document}

或者\fpeval?

\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
\foreach \ii in {0, 1, ..., 5}{
  \foreach \jj in {0, 1, ..., 4}{
    \def\x{\fpeval{\ii+\jj*0.5}}
    \def\y{\fpeval{-\jj*0.8}}
    \node at (\x,\y) {$(\ii,\jj)$};
  }
}
\end{tikzpicture}
\end{document}

利用luadraw还挺简单的,要实现「要求取点多但网格线少」好像也只要改一个参数...

\documentclass{standalone}
\usepackage[svgnames]{xcolor}
\usepackage[3d]{luadraw}
\usepackage{fourier}
\begin{document}
\begin{luadraw}{name=saddle}
local g = graph3d:new{
    window3d={-2,2,-2,2,-2,2}, 
    adjust2d=true,size={10,10}
}
local f = function(x,y) return 0.3*(x*x - y*y) end
local s = cartesian3d(f, -1.5, 1.5, -1.5, 1.5,{10,10})
-- The function cartesian3d(f, x1, x2, y1, y2 [, grid, addwall])
-- change the parameter grid to get less facets
g:Dboxaxes3d{grid=true}
g:Dfacet(s, {color="Orange", mode=mShaded})
g:Show()
\end{luadraw}
\end{document}

image.png

仅作示范,可以画两次,第二次不要画额外的轴:

\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}
  \pgfplotsset{set layers}
  \begin{axis}[
    scale only axis,
    width=10cm, height=6cm,
    ybar, bar width=12pt,
    ylabel={Production (10k tons)},
    symbolic x coords={1-2, 1-3, 1-4, 1-5, 1-6, 1-7, 1-8, 1-9},
    xtick=data,
    ymin=0, ymax=8000,
    axis y line*=left,
    legend style={at={(0.5,-0.15)}, anchor=north, legend columns=-1},
    area style
  ]
    \addplot[fill=white, draw=black] coordinates {
        (1-2, 1149) (1-3, 1744) (1-4, 2314) (1-5, 2905) 
        (1-6, 3526) (1-7, 4111) (1-8, 4672) (1-9, 5263)
    };
    \addplot[fill=gray!60, draw=black] coordinates {
        (1-2, 1527) (1-3, 2362) (1-4, 3143) (1-5, 3939) 
        (1-6, 4792) (1-7, 5584) (1-8, 6348) (1-9, 7160)
    };
    \legend{Pig Iron, Crude Steel}
  \end{axis}

  \begin{axis}[
    scale only axis,
    width=10cm,height=6cm,
    axis y line*=right,
    axis x line=none,
    ylabel={Growth Rate (\%)},
    ymin=0, ymax=16,
    symbolic x coords={1-2, 1-3, 1-4, 1-5, 1-6, 1-7, 1-8, 1-9}
  ]
    \addplot[mark=square*,thick] coordinates {
        (1-2, 7.1) (1-3, 8.0) (1-4, 6.8) (1-5, 5.8) 
        (1-6, 5.6) (1-7, 5.4) (1-8, 5.0) (1-9, 4.9)
    };
    \addplot[mark=triangle*,thick] coordinates {
        (1-2, 13.7) (1-3, 11.0) (1-4, 8.7) (1-5, 8.2) 
        (1-6, 9.3) (1-7, 9.5) (1-8, 9.3) (1-9, 9.3)
    };
  \end{axis}
\end{tikzpicture}
\end{document}

image.png

另外提问要给代码,即使你不能画出双轴,你也应给出绘制单轴的代码。

Claim: ⚠这是一个相当邪修的做法...

我不太确定这是否会造成其他恶劣影响,建议不要使用。

来自我的这个提问

\documentclass{article}
\usepackage[fontset=fandol]{ctex}
\usepackage{amsmath,amsfonts}
% https://ask.latexstudio.net/ask/question/17856.html
\begin{document}

    电磁学与电动力学的区别:
    \makeatletter
    \[
    \def\env@cases{%
      \let\@ifnextchar\new@ifnextchar
      \left\lbrace
      \def\arraystretch{0.5}%
      \array{@{}l@{\quad}l@{}}%
    }
    \makeatother
    \begin{cases}
        \text{电磁学:数学语言比较简单,通常只利用积分} 
        \vspace{10ex}\\
        \text{电动力学:大量使用矢量微分运算}
    \end{cases}
    \]

    \[
    y = \begin{cases}
        x+y+z \\
        x^2+y^2+z^2 
    \end{cases}
    \]
\end{document}

image.png

Notes: 永远不要在LaTeX里用$$...$$,使用\[...\]。详见这里

Claim:以下只记录我的尝试过程,仅供参考

image.png

Step1

image.png

Step2

image.png

Step3

image.png

(这里我不太确定要不要重启,可以试试...)

Step4

image.png

\documentclass{standalone}
\usepackage[3d]{luadraw}
\usepackage[svgnames]{xcolor}
\begin{document}

    \pgfdeclareradialshading[]{sphereDay}{\pgfpoint{20 bp}{0 bp}}
    {color(0bp)=(orange!10); color(20bp)=(orange!50); color(38bp)=(orange)}% 
    \pgfdeclareradialshading[]{sphereNight}{\pgfpoint{50 bp}{0 bp}}
    {color(0bp)=(DarkBlue!10); color(15bp)=(DarkBlue!70); color(38bp)=(black)}% 

    \begin{luadraw}{name=earth_light_half}
        local g = graph3d:new{
            window3d={-5, 5, -5, 5, -5, 5},
            window={-5 , 10, -5 ,5},
            size={8, 8},viewdir={90, 80}
        }

        require "luadraw_spherical"
        local O, R = Origin, 4
        Hiddenlines = true
        Hiddenlinestyle = "dashed"
        g:Define_sphere({radius=R, show=false})
        local thetaA, thetaB = 22.5, 67.5
        -- plot the latitudes
        for _,i in ipairs({90-thetaA, 90-thetaB, 90+thetaA, 90+thetaB})do
            local lat = sM(0,i)
            g:DScircle({lat,vecK}, {color="magenta", width=4})
        end
        -- plot the equator
        g:DSbigcircle({vecI,vecJ},{style="dashed", color="teal", width=5})
        -- plot the axis
        g:DSseg({ M(0,0,-1.25*R), M(0,0,1.25*R) }, {width=10})
        -- two hemispheres outlines
        local A, B = Z(0,R), Z(0,-R)
        g:Dpath({ B, "m", 0, A, R, -1, "ca"}, "color=DarkGray, shading=sphereNight")
        g:Dpath({ B, "m", 0, A, R, 1, "ca"}, "color=DarkGray, shading=sphereDay")

        g:Rotate3d(-22.5, {Origin,vecJ})
        g:Dspherical()

        local dt = 25*deg
        for k = 0, 4 do
            local z = Zp(R+1,(k-2)*dt)
            g:Dpolyline({Z(10,z.im), z}, false, "-latex,thick,teal")
        end
        g:Show()
    \end{luadraw}
\end{document}

image.png

术业有专攻,应该找找建筑设计行业的「最佳实践」。

image.png

试了一下现有的宏包, 都相去甚远, 有没有什么好的宏包推荐一下呢?

从代码的注释里我只看到了纯AI的痕迹,没看到太多尝试。而且这个图从构图来看并不存在很大的技术难点,只是细节多,绘制繁琐。

说实话用TikZ画这种图的意义几乎为零。

其实我感觉语法没有比tikz-3d简单,反而求两个大圆交点(在luadraw-v2.6)需要花点心思...

% https://github.com/pfradin/luadraw/discussions/223#discussioncomment-16064759
\documentclass{standalone}
\usepackage[3d]{luadraw}
\usepackage[svgnames]{xcolor}
\usepackage{fourier}
\begin{document}
    \begin{luadraw}{name=spherical_geometry}
    local g = graph3d:new{window3d={-5, 5, -5, 5, -5, 5},window={-3,4.25,-3,4}, viewdir={30, 65}, size={12, 12}}
    require 'luadraw_spherical'

    local O,R = Origin,4
    g:Define_sphere({radius=R, show=false, opacity=1})
    local Pz, Px, Py = sM(0,0), sM(0,90), sM(90,90)
    local theta = 55
    local A, B = sM(theta, 90), Py
    local D = sM(90,65)
    local M = 0.7 * D
    local N = pxy(M)

    -- calculus of C and K
    -- The function plane(A,B,C) returns the plane passing through the three 3d points A, B, and C (if they are not aligned,otherwise the result is nil).
    local d = interPP( plane(O,Px,D), plane(O,A,Pz) )
    -- the intersection of two planes is line OC
    -- d[2] is a direction vector of the line d
    -- where d is the line in form {A,u}, the normalized direction vector
    local C = R*pt3d.normalize(d[2]) 
    local K = pxy(C) -- projection of C on the plane Oxy

    Hiddenlines = true;Hiddenlinestyle = "dashed"
    g:Linestyle("dashed")

    -- g:DSarc({Pz, Px}, 1)
    -- g:DSarc({Pz, Py}, 1)
    -- g:DSarc({Px, Py}, 1)
    -- g:DSarc({Px, D}, 1)
    -- g:DSarc({Pz, A}, 1)
    for _, arc in ipairs({{Pz, Px}, {Pz, Py}, {Px, Py}, {Px, D}, {Pz, A}}) do
        g:DSarc(arc, 1)
    end

    -- g:DSseg({O, Pz})    
    -- g:DSseg({O, Px})
    -- g:DSseg({O, Py})
    -- g:DSseg({N, K})
    -- g:DSseg({M, N})

    g:DSpolyline({{Px,O,Pz},{M,N,K},{O,B}})

    g:Linestyle("solid"); Hiddenlinestyle = "solid"
    g:DSseg({O, A})    
    g:DSseg({O, D})
    g:DSseg({O, C})
    g:DSseg({C, K})
    g:DSseg({C, M})
    g:DSarc({A, B}, 1)

    g:DSdots({O,A,D,M,N},{mark_options="teal"}) 
    g:DSstars({Pz, Px, Py}, {color="magenta",fill="magenta", scale=0.75}) 
    g:Dspherical()

    g:Dlabel3d(
        "$O$", O, {pos="W"}, 
        "$A$", A, {pos="S"}, 
        "$B$", B, {pos="E"}, 
        "$C$", C, {pos="NW"}, 
        "$D$", D, {pos="NE"}, 
        "$K$", K, {pos="W"}, 
        "$M$", M, {pos="N"}, 
        "$N$", N, {pos="NE"}
    )
    g:Show()
    \end{luadraw}
\end{document}

image.png

这个模板只有一些文件名不匹配的小问题,自行修改即可。

https://github.com/fylimas/nsfc/issues/73

也许是精度误差(?)

\documentclass[tikz]{standalone}
\begin{document}
    \begin{tikzpicture}
        \node {\fpeval{tand(45)} v.s. \pgfmathparse{tan(45)}\pgfmathresult};
    \end{tikzpicture}
\end{document}        

image.png

发布
问题