如何減少 tikzpicture 中條目之間的間距?

如何減少 tikzpicture 中條目之間的間距?

對於我的簡歷,我想使用一些技能欄

但由於我的佈局是固定的,我需要調整條目之間的空間。

這是一個 MWE:

\documentclass{report}

\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{xcolor}

\definecolor{white}{RGB}{255,255,255}
\definecolor{gray}{HTML}{4D4D4D}
\definecolor{maingray}{HTML}{B9B9B9}

\newcommand\skills[1]{ 
    \begin{tikzpicture}
        \foreach [count=\i] \x/\y in {#1}{
            \draw[fill=maingray,maingray] (0,\i) rectangle (6,\i+0.4);
            \draw[fill=white,gray](0,\i) rectangle (\y,\i+0.4);
            \node[above right] at (0,\i+0.4) {\x};
        }
    \end{tikzpicture}
}

\begin{document}
\skills{{a/1},{b/2}}
\end{document}

如何更改程式碼來定義/減少兩個條目之間的空間?

答案1

在此輸入影像描述

您需要減小大小,例如\i將其乘以0.8

\documentclass{report}

\usepackage[T1]{fontenc}
\usepackage{tikz}
\usepackage{xcolor}

\definecolor{white}{RGB}{255,255,255}
\definecolor{gray}{HTML}{4D4D4D}
\definecolor{maingray}{HTML}{B9B9B9}

\newcommand\skills[1]{
    \begin{tikzpicture}
        \foreach [count=\j, evaluate={\i=\j*0.8}] \x/\y in {#1}{
            \draw[fill=maingray,maingray] (0,\i) rectangle +(6,0.4); % <---
            \draw[fill=white,gray](0,\i) rectangle +(\y,0.4);% <---
            \node[above right] at (0,\i+0.4) {\x};% <---
        }
    \end{tikzpicture}
}

\begin{document}
\skills{{a/1},{b/2}}
\end{document}

相關內容