我想使用 latex 环境绘制类似附图的图形。我知道可以使用其他软件(例如 CAD)来实现,但 LaTex 创建的图形看起来更漂亮。有人能帮帮我吗?
PS:不必与附图完全相同。
答案1
好吧,这就是您的图表所展示的大部分内容。我在整个过程中添加了一些注释,希望可以帮助您更好地理解我所做的工作。
我大量使用了该calc
库。我还使用该patterns
库来获取边矩形内的点。
\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{patterns}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
%% defining the corners of the grill
\coordinate (grill/sw) at (0,0);
\coordinate (grill/ne) at ($(grill/sw)+(5in,1cm)$);
\coordinate (grill/nw) at (grill/sw|-grill/ne);
\coordinate (grill/se) at (grill/sw-|grill/ne);
%% filling the grill
\draw[fill=gray!20] (grill/sw) rectangle (grill/ne);
%% drawing the horizontal bars of the grill
\def\mymax{7}
\foreach \myn in {0,1,...,\mymax}
{
\draw ($(grill/sw)!\myn/\mymax!(grill/nw)$)
-- ($(grill/se)!\myn/\mymax!(grill/ne)$);
}
%% material above the grill
%% downward arrows
\def\myarrowheight{1cm}
\def\myarrowcount{12}
\foreach \myn in {0,1,...,\myarrowcount}
{
\draw[arrows=Stealth-] ($(grill/nw)!\myn/\myarrowcount!(grill/ne)$) -- ++ (0,\myarrowheight);
}
%% label above downward arrows
\path ([yshift=\myarrowheight+2ex]grill/nw) --
([yshift=\myarrowheight+2ex]grill/ne)
node[midway] {$q$};
%% material below the grill
%% grill label
\path (grill/sw) -- (grill/se) node[midway,below] {$E_r,E_m,\rho_r,\rho_m,f$};
%% corner decorations
%% isosceles triangle
\def\myr{1.5ex}
\draw[fill=red] (grill/sw) -- ++ (-60:{\myr*2/sin(60)})
-- ++ (180:{\myr*2/sin(60)})
-- cycle;
%% circle
\draw[fill=red] ($(grill/se)+(down:\myr)$) circle (\myr);
%% hash marks under corner decorations
\begin{scope}[myyshift/.style={yshift={-2*\myr}}]
\def\mystepmax{4}
\def\mystepwidth{5pt}
\def\mystepheight{6pt}
\foreach \myside in {se,sw}
{
\foreach \myn in {1,...,\mystepmax}
{
\pgfmathsetmacro\myxshift{ (-\mystepmax /2+\myn)*\mystepwidth -\mystepwidth}
\draw ([myyshift,xshift=\myxshift]grill/\myside) --
([myyshift,xshift={\myxshift+\mystepwidth}]grill/\myside) --
([myyshift,yshift=-\mystepheight,xshift=\myxshift]grill/\myside);
}
}
\end{scope}
\pgfmathsetmacro\myyshift{5ex+2*\myr}
\begin{scope}[myshift/.style={yshift={-\myyshift}}]
\path
([myshift]grill/sw)
--
([myshift]grill/se)
node [midway] {L}
edge[arrows=->] ([myshift]grill/se)
edge[arrows=->] ([myshift]grill/sw);
\foreach \myn in {se,sw}
{
\draw ([myshift]grill/\myn)
edge ++(up:3ex)
edge ++(down:3ex);
}
\end{scope}
\draw ($(grill/ne)+(1cm,0)$) rectangle ($(grill/se)+(1.5cm,0)$);
\pattern[pattern=crosshatch dots gray] ($(grill/ne)+(1cm,0)$) rectangle ($(grill/se)+(1.5cm,0)$);
\end{tikzpicture}
\end{document}
完成图表所需了解的技术已在上面的代码中进行了演示。
我做过的一些事情可能还有更简单(更好)的方法。我把这个留给更熟悉技巧的人TikZ
来演示。