如何减少Latex中标题和图形之间的间隙

如何减少Latex中标题和图形之间的间隙

请帮我缩小代码中图形和标题之间的间隙。我尝试使用位置说明符,如 h! 或 H,但它们会将图形稍微移到标题上。我尝试使用 vspace*,但结果也一样。所以,请帮帮我。

\documentclass{article}
\usepackage{xcolor}
\usepackage{pgfplots}
\usepackage{tikz}
\usepackage{layout}
\usepackage{float}
\usepackage{fancyhdr,adjustbox}
\usepackage{subfig}
\usepackage{titlesec}
\usepackage[margin=0.5in]{geometry}
\usepackage{colortbl}
\usepackage{filecontents}
\usepackage{array}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage[font=small,compatibility=false]{caption}
\usepackage[english]{babel}
\usepackage[T1]{fontenc}

\pagestyle{fancy}
\fancyhf{}
\renewcommand{\headrulewidth}{0pt}
\lhead{\includegraphics[scale=0.4]{headerpic.jpg}}
\chead{}
\rhead{ 10th }
\addtolength{\topmargin}{.1in}
\definecolor{bblue2}{HTML}{00BFFF}
\definecolor{bblue}{HTML}{4F81BD}
\definecolor{rred}{HTML}{C0504D}
\definecolor{ggreen}{HTML}{9BBB59}
\definecolor{ppurple}{HTML}{eb6100}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
    \begin{axis}[
        axis x line=bottom,
        axis y line=left,
        width  = 0.85*\textwidth,
        height = 8cm,
        major x tick style = transparent,
        ybar,
        bar width=20pt,
        ymajorgrids = true,
        ylabel = {K Score},
        symbolic x coords={ 
        learning,engagement,safety,collaboration 
        },
        xtick = data,
        scaled y ticks = false,
        enlarge x limits=0.25,
        ymin=0,
        legend cell align=left,
        nodes near coords,
        nodes near coords align={vertical},
        legend style={
                at={(1,1.05)},
                anchor=south east,
                column sep=1ex
        }
    ]
        \addplot[style={bblue2,fill=bblue2,mark=none}]
            coordinates {
            (learning,3.94) (engagement,4.17) (safety,3.44) (collaboration,4.32)
            };

        \legend{Categories}
    \end{axis}
\end{tikzpicture}
    \caption{\textit{Overall Metrics} }
\end{figure}
\end{document}

在此处输入图片描述

答案1

LaTeX 将跳过寄存器\@fptop\@fpbot放在浮动列/页面的顶部和底部以及\@fpsep它们之间。默认值为:

\setlength\@fptop{0\p@ \@plus 1fil}% = 0pt plus 1fil
\setlength\@fpsep{8\p@ \@plus 2fil}% = 8pt plus 2fil
\setlength\@fpbot{0\p@ \@plus 1fil}% = 0pt plus 1fil

这意味着浮动元素在浮动页面上垂直居中。

通过设置\@fptop为零而不使用拉伸分量,最上面的浮动将移动到顶部:

\makeatletter
\setlength{\@fptop}{0pt}
\makeatother

相关内容