使用 svg 包和 inkscape 将 svg 转换为 tex:使文本在形状内换行

使用 svg 包和 inkscape 将 svg 转换为 tex:使文本在形状内换行

我使用 LuaLaTeX(最新的 MikTeX +TexStudio),并希望在我的文档中使用在 MS Visio 中创建的 SVG 插图。这是原始图像

作为快速和污垢修复我对 svg 包的问题我使用批处理文件手动启动 inkskape,方式与 svg 包相同

@echo off
"C:\Program Files\Inkscape\inkscape.exe" -z -D -f %1 -A "%~dpn1.pdf" --export-latex

并编译文档。以下是它在 PDF 中的样子。 结果图像

看起来相当不错:形状正确,字体根据文档的字体进行了调整,并在适当位置进行了放大。除了它没有在形状内换行之外。强制换行的尝试\newline被忽略。以下是 pdf_tex 文件的内容

\begingroup%
  \makeatletter%
  \providecommand\color[2][]{%
    \errmessage{(Inkscape) Color is used for the text in Inkscape, but the package 'color.sty' is not loaded}%
    \renewcommand\color[2][]{}%
  }%
  \providecommand\transparent[1]{%
    \errmessage{(Inkscape) Transparency is used (non-zero) for the text in Inkscape, but the package 'transparent.sty' is not loaded}%
    \renewcommand\transparent[1]{}%
  }%
  \providecommand\rotatebox[2]{#2}%
  \ifx\svgwidth\undefined%
    \setlength{\unitlength}{497.74924049bp}%
    \ifx\svgscale\undefined%
      \relax%
    \else%
      \setlength{\unitlength}{\unitlength * \real{\svgscale}}%
    \fi%
  \else%
    \setlength{\unitlength}{\svgwidth}%
  \fi%
  \global\let\svgwidth\undefined%
  \global\let\svgscale\undefined%
  \makeatother%
  \begin{picture}(1,0.40658965)%
    \put(0,0){\includegraphics[width=\unitlength,page=1]{system_abstract.pdf}}%
    \put(0.41094927,0.3789432){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{\large{Measurement board}}}}%
    \put(0,0){\includegraphics[width=\unitlength,page=2]{system_abstract.pdf}}%
    \put(0.85230537,0.31601965){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{\large{Battery}}}}%
    \put(0,0){\includegraphics[width=\unitlength,page=3]{system_abstract.pdf}}%
    \put(0.06182823,0.21124862){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{{\large Raspberry PI 2}\newline Reads the data and adjusts the current}}}%
    \put(0,0){\includegraphics[width=\unitlength,page=4]{system_abstract.pdf}}%
    \put(0.53429834,0.28286294){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{Current Actuator}}}%
    \put(0,0){\includegraphics[width=\unitlength,page=5]{system_abstract.pdf}}%
    \put(0.35378604,0.2015892){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{SPI}}}%
    \put(0,0){\includegraphics[width=\unitlength,page=6]{system_abstract.pdf}}%
    \put(0.51717328,0.11581522){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{Ammeter+Voltmeter}}}%
    \put(0,0){\includegraphics[width=\unitlength,page=7]{system_abstract.pdf}}%
  \end{picture}%
\endgroup%

有办法修复吗?可能是在图片中添加一些额外的 LaTeX 代码?

答案1

您可以手动将文本分成两行:

\documentclass{article}

\usepackage{graphicx}
\usepackage{xcolor}

\begin{document}

\setlength{\unitlength}{497.74924049bp}%
\begin{picture}(1,0.40658965)%
  \put(0.06182823,0.21124862){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{{\large Raspberry PI 2}}}}%
  \put(0.06182823,0.18){\color[rgb]{0,0,0}\makebox(0,0)[lb]{\smash{Reads the data and adjusts the current}}}%
\end{picture}%

\end{document}

或者,您可以将 包装在\parbox适当宽度中以实现自动换行:

\documentclass{article}

\usepackage{graphicx}
\usepackage{xcolor}

\begin{document}

\setlength{\unitlength}{497.74924049bp}%
\begin{picture}(1,0.40658965)%
  \put(0.06182823,0.21124862){%
    \parbox{3cm}{%  
        {\large Raspberry PI 2}
        Reads the data and adjusts the current
    }%
  }%
\end{picture}%

\end{document}

相关内容