2

Please help me reduce the gap between the figure and the header in my code. I tried using position specifiers like h! or H but those take the figure on to the header slightly. I tried using vspace* but that also gave the same result. So, please help me.

\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}

enter image description here

1 Answers1

4

LaTeX puts the skip registers \@fptop and \@fpbot at the top and bottom of float columns/pages and \@fpsep between them. The default values are:

\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

That means, the floats are vertically centered on float pages.

By setting \@fptop to zero without stretch component, the uppermost float is moved to the top:

\makeatletter
\setlength{\@fptop}{0pt}
\makeatother
Heiko Oberdiek
  • 271,626