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条回答
U9430
2020-11-04 18:03
```c \definecolor{lblue}{RGB}{51,153,255} \definecolor{dgray}{RGB}{224,224,224} \definecolor{lgreen}{RGB}{72,194,169} 我是一个东西 \begin{tikzpicture}[baseline={($(current bounding box.center)+(0,-0.5em)$)}] \def\linelength{4} \draw [dgray,line width=2mm,line cap=round](0,0)--+(\linelength,0) node [black,right] {20\%}; \draw [lblue,line width=2mm,line cap=round](0,0)--+(0.8*\linelength,0); \draw [dgray,line width=2mm,line cap=round](0,-0.5)--+(\linelength,0) node [black,right] {50\%}; \draw [lblue,line width=2mm,line cap=round](0,-0.5)--+(0.5*\linelength,0); \end{tikzpicture} ```

一周热门 更多>