![如何更改 MetaPost 的字体?](https://linux22.com/image/461675/%E5%A6%82%E4%BD%95%E6%9B%B4%E6%94%B9%20MetaPost%20%E7%9A%84%E5%AD%97%E4%BD%93%EF%BC%9F.png)
我有以下代码来使用 MetaUML 创建 UML 图:
\begin{mpost}[mpsettings=input metauml;]
Class.Task("Task")
(
"-id: long",
"-name: String"
)
(
"+Task(name: String)",
"+Task(id: long, name: String)",
"+getId(): long",
"+getName(): String",
"+setName(name: String): void"
);
drawObjects(Task);
\end{mpost}
从技术上讲,UML 图显示正确,但它使用某种默认衬线字体(我认为是 Times New Roman)。我希望它具有与文档其余部分相同的无衬线字体,我已通过以下方式定义
\renewcommand{\familydefault}{\sfdefault}
\usepackage{sourcesanspro}
这对于文档的其余部分来说很好,但遗憾的是不适用于该mbox
部分。还有两件事:
- 我不知道这是否有影响,但我正在使用 pdfLaTex
- 我已经检查过这个答案,但不幸的是它没有帮助:如何更改 metauml 的字体?
答案1
万一您能够切换到lualatex
,这里有一种方法可以获取您想要的东西:
\documentclass{article}
\usepackage{sourcesanspro}
\renewcommand{\familydefault}{\sfdefault}
\usepackage{luamplib}
\everymplib{input metauml; beginfig(0);}
\everyendmplib{endfig;}
\mplibtextextlabel{enable}
\begin{document}
Similarly, the incorporation of additional mission constraints must utilize and be
functionally interwoven with the total system rationale. In theory, the
interrelation of system and/or subsystem technologies must utilize and be
functionally interwoven with the preliminary qualification limit.
\[\begin{mplibcode}
Class.Task("Task")
(
"-id: long",
"-name: String"
)
(
"+Task(name: String)",
"+Task(id: long, name: String)",
"+getId(): long",
"+getName(): String",
"+setName(name: String): void"
);
drawObjects(Task);
\end{mplibcode}\]
In particular, any associated supporting element necessitates that urgent
consideration be applied to possible bidirectional logical relationship approaches.
Conversely, any associated supporting element recognizes other systems' importance
and the necessity for possible bidirectional logical relationship approaches.
However, a service-oriented paradigm is further compounded when taking into account
the evolution of specifications over a given time period.
\end{document}
编译此文件lualatex
可获得如下 PDF:
更多信息请luamplib
参见这里。
要缩小字体,您可以metauml
调整一些设置,但最后缩放当前图片可能更简单。因此,您可以通过添加
currentpicture := currentpicture scaled 0.8;
在环境结束之前。如果您想对每个图表都执行此操作,那么您可以更新序言以说明:
\everyendmplib{currentpicture := currentpicture scaled 0.8; endfig;}
或者,由于mplibcode
环境继承自周围的 LaTeX 环境,您可以将每张图片括在一个具有较小字体的组中:
\[{\small\begin{mplibcode}
...
\end{mplibcode}}\]