tikz绘制内容和前后文字垂直对齐

2020-11-04 10:51发布

## 编译环境 操作系统 * [x] Windows 7/8/10 * [ ] macOS * [ ] Linux `若需勾选,请把[ ]改成[x]` Tex发行版 * [x] TexLive `年...

## 编译环境 操作系统 * [x] Windows 7/8/10 * [ ] macOS * [ ] Linux `若需勾选,请把[ ]改成[x]` Tex发行版 * [x] TexLive `年份` * [ ] MikTeX `版本号` * [ ] CTeX `若需勾选,请把[ ]改成[x]` ## 我的问题 ````markdown \documentclass[10pt]{article} \usepackage[paperwidth=21cm,paperheight=29.7cm,top=0.8cm,bottom=0.8cm,left=0.8cm,right=0.8cm]{geometry} \usepackage[UTF8]{ctex} \usepackage{pgfplots} \usepackage{color} \pagestyle{empty} \definecolor{lblue}{RGB}{51,153,255} \definecolor{dgray}{RGB}{224,224,224} \definecolor{lgreen}{RGB}{72,194,169} \begin{document} 我是一个东西 \begin{tikzpicture}[baseline] \draw (4.1cm, 0.4mm) node [anchor=mid west] {20\%}; \fill (0,0) [fill=dgray, rounded corners=0.1cm] rectangle ++(4cm, 0.2cm); \fill (0,0) [fill=lblue, rounded corners=0.1cm] rectangle ++(3cm, 0.2cm); \draw (4.1cm, -4mm) node [anchor=mid west] {50\%}; \fill (0,-0.5cm) [fill=dgray, rounded corners=0.1cm] rectangle ++(4cm, 0.2cm); \fill (0,-0.5cm) [fill=lgreen, rounded corners=0.1cm] rectangle ++(2cm, 0.2cm); \end{tikzpicture} \\ \end{document} ```` ![](https://wenda.latexstudio.net/data/attach/201104/h7GJL7nP.png) 左侧的文字怎么和右侧整体垂直居中对齐啊
2条回答
逆天小白兔
2020-11-04 11:18
可以用`minipage`整一下 ```tex \documentclass[10pt]{article} \usepackage[paperwidth=21cm,paperheight=29.7cm,top=0.8cm,bottom=0.8cm,left=0.8cm,right=0.8cm]{geometry} \usepackage[UTF8]{ctex} \usepackage{pgfplots} \usepackage{color} \pagestyle{empty} \definecolor{lblue}{RGB}{51,153,255} \definecolor{dgray}{RGB}{224,224,224} \definecolor{lgreen}{RGB}{72,194,169} \begin{document} \begin{minipage}{.14\linewidth} 我是一个东西 \end{minipage} \begin{minipage}{.4\linewidth} \begin{tikzpicture} \draw (4.1cm, 0.4mm) node [anchor=mid west] {20\%}; \fill (0,0) [fill=dgray, rounded corners=0.1cm] rectangle ++(4cm, 0.2cm); \fill (0,0) [fill=lblue, rounded corners=0.1cm] rectangle ++(3cm, 0.2cm); \draw (4.1cm, -4mm) node [anchor=mid west] {50\%}; \fill (0,-0.5cm) [fill=dgray, rounded corners=0.1cm] rectangle ++(4cm, 0.2cm); \fill (0,-0.5cm) [fill=lgreen, rounded corners=0.1cm] rectangle ++(2cm, 0.2cm); \end{tikzpicture} \end{minipage} \end{document} ``` 效果如下图 ![](https://wenda.latexstudio.net/data/attach/201104/77Wj9Hsm.png)

一周热门 更多>