今天看啥  ›  专栏  ›  LaTeX工作室

tikz中如何测量给定node的宽度和高度?

LaTeX工作室  · 公众号  ·  · 2024-08-08 19:13

文章预览

选自: https://ask.latexstudio.net/ask/question/17311.html 【如题】 造了个轮子 \documentclass{article} \usepackage{tikz} \usetikzlibrary{calc} \ begin {document} \makeatletter \ def \ pgfgetnodeheight ( #1)#2{ \path ($( #1.south) - (#1.north)$); \pgfmathsetmacro #2{veclen(\pgf @x , \pgf @y )} \edef #2{#2pt} } \ def \ pgfgetnodewidth ( #1)#2{ \path ($( #1.east) - (#1.west)$); \pgfmathsetmacro #2{veclen(\pgf @x , \pgf @y )} \edef #2{#2pt} } \makeatother \ begin {tikzpicture} \node[anchor = south west, draw, align = left] (a) {text width \\ text width}; \pgfgetnodewidth(a) \nWidth \pgfgetnodeheight(a)\nHeight \draw[red] ( 0 , -. 1 ) -- (\nWidth, -. 1 ) node[midway, below, text = black] {\nWidth};; \draw[blue] (-. 1 , 0 ) -- (-. 1 , \nHeight) node[midway, left, text = black] {\nHeight}; \ end {tikzpicture} \ end {document} 关注我们公众号,学习 LaTeX 无烦恼! 入门资料,免费知识代码: https://flowus.cn/latex/share/66110e84-b24a-4c ………………………………

原文地址:访问原文地址
快照地址: 访问文章快照
总结与预览地址:访问总结与预览