[Tex/LaTex] Force subsection onto the same page as table

landscapetables

I want to force my subsection onto the same page as the table.

The table seems to be too big for doing it automatically.
I could use \resizebox to shrink the table, but I used \landscapeto avoid that.

Is there a way to do this? Maybe enlarging the invisible textborders of the page?
Any suggestions?

\documentclass[a4paper, 11pt, parskip]{scrreprt}
\KOMAoption{listof}{totoc}%adds \listoffigures and \listoftables to the toc
\KOMAoption{appendixprefix}{true}%i think its for colon at appendix toc
\RedeclareSectionCommand[beforeskip=0pt,%to have smaller spacing before chapter texts
afterskip=2cm]{chapter}
\renewcommand{\autodot}{}% Remove all end-of-counter dots


\usepackage{scrhack}%\float@addtolists detected! Behebt die Warnung.
\usepackage{ucs}% Für den erweiterten utf8 Zeichensatz
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}% Für \lipsum
\usepackage{tikz-timing}[2009/05/15]% Für Zeitablaufdiagramme http://www.texample.net/tikz/examples/tikz-timing/
\usepackage{tikz}%drawing stuff
\usetikzlibrary{positioning}
\usepackage{cite}
\usepackage[]{acronym}%Abkürzungsverzeichnis
\usepackage[bwr]{callouts}%for simple drawings in pictures
\usepackage{url}% for pathnames
\usepackage{dirtree}%for directory trees
\usepackage{makecell}%To keep spacing of text in tables
\usepackage{colortbl}%coloring tables
\usepackage{xcolor}
\usepackage{pdflscape}
%------------------------------------------------------------------------------------------------
% fonts, fonts fonts. see https://tex.stackexchange.com/questions/43881/how-to-correctly-use-the-palatino-font-in-memoir
% Pagella (Palatino clone) font for text, pazo for math
\usepackage[sc]{mathpazo} % use mathpazo for math fonts.
\usepackage{tgpagella} % but use tgpagella as main font
\usepackage[scaled=0.75]{luximono}
\usepackage{inconsolata}

\normalfont % we want to avoid annoying warnings
\DeclareFontShape{T1}{qpl}{m}{sl} { <-> ssub * qpl/m/it }{}
\DeclareFontShape{T1}{qpl}{b}{sl} { <-> ssub * qpl/b/it }{}

% heros (Helvetica clone) for sans serif
\usepackage{tgheros}%   Serifenlose Schrift für Überschriften. 
%------------------------------------------------------------------------------------------------
\usepackage[ngerman]{babel}          
\usepackage{graphicx}%bilder einfügen
\usepackage{caption, booktabs}
\usepackage{multirow}
\usepackage{color}  %farben für listings
\definecolor{mygreen}{rgb}{0,0.5,0}
\definecolor{Gray}{gray}{0.85}



\begin{document}
\begin{landscape}
    \subsection{X400/PortA/Relaisplatine 1}
    Portextension 1: X400/PortA\\
    Labeled with Number 1.
    \begin{table}[h]
        %\makegapedcells
        \centering
        %\resizebox{\textwidth}{!}{%resizing the whole table
    \begin{tabular}{|c|c|c|c|c|c|c|c|c|}
        %\multicolumn{9}{c}{text}\\
        \hline
        \multicolumn{9}{|c|}{\gape{\Huge Relaisplatine}} \\ 
        \hline
        Relay Nr. & Part & Test-Id & \makecell[c]{Signal-Name \\for Testcases} & Conn. & Pin & \makecell[c]{Pin-\\Func.} & R Value & \makecell[c]{Influenced \\ Signal/Voltage } \\ 
        \hline 
        \cline{6-9} 
        %\hline 
        0 & RIO & RIO\_VOLT\_SDAR & RIO\_GPP\_VCORE & P2 & 3 & COM &  0 $\Omega$ & SIGN08116 \\
        \cline{6-9}  
        %\hline 
        &  &  &  &  & 5 & N.O. &  0 $\Omega$ & GND \\
        %\cline{6-9}  
        \hline 
        &  &  &  &  & 7 & N.C. &  Open & Open \\ 
        \cline{6-9} 
        1 & RIO & RIO\_VOLT\_SDAR & RIO\_ETH\_+1V2 & P2 & 9 & COM &  0 $\Omega$ & SIGN0818 \\ 
        \cline{6-9}
        &  &  &  &  & 11 & N.O. &  0 $\Omega$ & GND \\ 
        \hline 
        &  &  &  &  & 13 & N.C. &  Open & Open \\ 
        \cline{6-9} 
        2 & RIO & RIO\_VOLT\_SDAR & RIO\_CLOCK\_+3V3 & P2 & 15 & COM &  0 $\Omega$ & SIGN0817 \\ 
        \cline{6-9} 
        &  &  &  &  & 17 & N.O. &  0 $\Omega$ & GND \\ 
        \hline 
        &  &  &  &  &  & N.C. &  Open & Open \\ 
        \cline{6-9} 
        3 & RIO & RIO\_VOLT\_SDAR & RIO\_HICURR1 & P3 & PCB-Cable & COM &  0 $\Omega$ & RIO\_+3V3 \\ 
        \cline{6-9} 
        &  &  &  &  & PCB-Cable & N.O. &  0 $\Omega$ & GND \\ 
        \hline 
        &  &  &  &  &  & N.C. &  Open & Open \\ 
        \cline{6-9} 
        4 & RIO & RIO\_VOLT\_SDAR & RIO\_HICURR2 & P3 & PCB-Cable & COM &  0 $\Omega$ & RIO\_+3V3 \\ 
        \cline{6-9} 
        &  &  &  &  & PCB-Cable & N.O. &  0 $\Omega$ & GND \\ 
        \hline 
        &  &  &  &  & 14 & N.C. &  Open & Open \\ 
        \cline{6-9} 
        5 & RIO & RIO\_VOLT\_SDAR & BAT\_LOW TBD & P2 & 16 & COM &  0 $\Omega$ & TBD \\ 
        \cline{6-9} 
        &  &  &  &  & 18 & N.O. &  0 $\Omega$ &  \\ 
        \hline 
        &  &  &  &  & 8 & N.C. &  Open & Open \\ 
        \cline{6-9} 
        6 & RIO & RIO\_VOLT\_SDAR & BAT\_EMPTY TBD & P2 & 10 & COM &  0 $\Omega$ & TBD \\ 
        \cline{6-9} 
        &  &  &  &  & 12 & N.O. &  0 $\Omega$ &  \\ 
        \hline 
        &  &  &  &  & 2 & N.C. &  Open & Open \\ 
        \cline{6-9} 
        7 & RIO & RIO\_VOLT\_SDAR & RIO\_DSP\_+3V3 & P2 & 4 & COM &  0 $\Omega$ & SIGN08150 \\ 
        \cline{6-9} 
        &  &  &  &  & 6 & N.O. &  0 $\Omega$ & Open \\ 
        \hline 
    \end{tabular}%
        %}%
    \caption{Verkabelung der ersten Relaisplatine an X400/PortA}
    \label{tab:x400}
    \end{table}
\end{landscape}
\end{document}

enter image description here

Best Answer

Here is one possible solution using the adjustwidth environment from the changepage package, which allows you to transiently reduce the page margins. Together with a reduction in font size, you can do away with the landscape format. If you want to keep the landscape, I would suggest to not put the section title there, as it may confuse the reader.

I commented out a couple of packages that were not found on my system, but I don't suppose it makes a difference.

\documentclass[a4paper, 11pt, parskip]{scrreprt}
\KOMAoption{listof}{totoc}%adds \listoffigures and \listoftables to the toc
\KOMAoption{appendixprefix}{true}%i think its for colon at appendix toc
\RedeclareSectionCommand[beforeskip=0pt,%to have smaller spacing before chapter texts
afterskip=2cm]{chapter}
\renewcommand{\autodot}{}% Remove all end-of-counter dots


\usepackage{scrhack}%\float@addtolists detected! Behebt die Warnung.
\usepackage{ucs}% Für den erweiterten utf8 Zeichensatz
\usepackage[utf8x]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{lipsum}% Für \lipsum
\usepackage{tikz-timing}[2009/05/15]% Für Zeitablaufdiagramme http://www.texample.net/tikz/examples/tikz-timing/
\usepackage{tikz}%drawing stuff
\usetikzlibrary{positioning}
\usepackage{cite}
\usepackage[]{acronym}%Abkürzungsverzeichnis
%\usepackage[bwr]{callouts}%for simple drawings in pictures
\usepackage{url}% for pathnames
\usepackage{dirtree}%for directory trees
\usepackage{makecell}%To keep spacing of text in tables
\usepackage{colortbl}%coloring tables
\usepackage{xcolor}
\usepackage{pdflscape}
%------------------------------------------------------------------------------------------------
% fonts, fonts fonts. see https://tex.stackexchange.com/questions/43881/how-to-correctly-use-the-palatino-font-in-memoir
% Pagella (Palatino clone) font for text, pazo for math
\usepackage[sc]{mathpazo} % use mathpazo for math fonts.
\usepackage{tgpagella} % but use tgpagella as main font
%\usepackage[scaled=0.75]{luximono}
%\usepackage{inconsolata}

\normalfont % we want to avoid annoying warnings
\DeclareFontShape{T1}{qpl}{m}{sl} { <-> ssub * qpl/m/it }{}
\DeclareFontShape{T1}{qpl}{b}{sl} { <-> ssub * qpl/b/it }{}

% heros (Helvetica clone) for sans serif
\usepackage{tgheros}%   Serifenlose Schrift für Überschriften. 
%------------------------------------------------------------------------------------------------
\usepackage[ngerman]{babel}          
\usepackage{graphicx}%bilder einfügen
\usepackage{caption, booktabs}
\usepackage{multirow}
\usepackage{color}  %farben für listings
\definecolor{mygreen}{rgb}{0,0.5,0}
\definecolor{Gray}{gray}{0.85}

\usepackage{changepage, lipsum}

\begin{document}

    \chapter{Stuff}

    \lipsum[1-2]

    \section{More stuff}

    \lipsum[3-4]

    \subsection{X400/PortA/Relaisplatine 1}
    Portextension 1: X400/PortA\\
    Labeled with Number 1.

    \begin{table}[h]
        %\makegapedcells
    \begin{adjustwidth}{-8em}{-8em}
    \centering\small % or try \footnotesize
    \begin{tabular}{|c|c|c|c|c|c|c|c|c|}
        %\multicolumn{9}{c}{text}\\
        \hline
        \multicolumn{9}{|c|}{\gape{\Huge Relaisplatine}} \\ 
        \hline
        Relay Nr. & Part & Test-Id & \makecell[c]{Signal-Name \\for Testcases} & Conn. & Pin & \makecell[c]{Pin-\\Func.} & R Value & \makecell[c]{Influenced \\ Signal/Voltage } \\ 
        \hline 
        \cline{6-9} 
        %\hline 
        0 & RIO & RIO\_VOLT\_SDAR & RIO\_GPP\_VCORE & P2 & 3 & COM &  0 $\Omega$ & SIGN08116 \\
        \cline{6-9}  
        %\hline 
        &  &  &  &  & 5 & N.O. &  0 $\Omega$ & GND \\
        %\cline{6-9}  
        \hline 
        &  &  &  &  & 7 & N.C. &  Open & Open \\ 
        \cline{6-9} 
        1 & RIO & RIO\_VOLT\_SDAR & RIO\_ETH\_+1V2 & P2 & 9 & COM &  0 $\Omega$ & SIGN0818 \\ 
        \cline{6-9}
        &  &  &  &  & 11 & N.O. &  0 $\Omega$ & GND \\ 
        \hline 
        &  &  &  &  & 13 & N.C. &  Open & Open \\ 
        \cline{6-9} 
        2 & RIO & RIO\_VOLT\_SDAR & RIO\_CLOCK\_+3V3 & P2 & 15 & COM &  0 $\Omega$ & SIGN0817 \\ 
        \cline{6-9} 
        &  &  &  &  & 17 & N.O. &  0 $\Omega$ & GND \\ 
        \hline 
        &  &  &  &  &  & N.C. &  Open & Open \\ 
        \cline{6-9} 
        3 & RIO & RIO\_VOLT\_SDAR & RIO\_HICURR1 & P3 & PCB-Cable & COM &  0 $\Omega$ & RIO\_+3V3 \\ 
        \cline{6-9} 
        &  &  &  &  & PCB-Cable & N.O. &  0 $\Omega$ & GND \\ 
        \hline 
        &  &  &  &  &  & N.C. &  Open & Open \\ 
        \cline{6-9} 
        4 & RIO & RIO\_VOLT\_SDAR & RIO\_HICURR2 & P3 & PCB-Cable & COM &  0 $\Omega$ & RIO\_+3V3 \\ 
        \cline{6-9} 
        &  &  &  &  & PCB-Cable & N.O. &  0 $\Omega$ & GND \\ 
        \hline 
        &  &  &  &  & 14 & N.C. &  Open & Open \\ 
        \cline{6-9} 
        5 & RIO & RIO\_VOLT\_SDAR & BAT\_LOW TBD & P2 & 16 & COM &  0 $\Omega$ & TBD \\ 
        \cline{6-9} 
        &  &  &  &  & 18 & N.O. &  0 $\Omega$ &  \\ 
        \hline 
        &  &  &  &  & 8 & N.C. &  Open & Open \\ 
        \cline{6-9} 
        6 & RIO & RIO\_VOLT\_SDAR & BAT\_EMPTY TBD & P2 & 10 & COM &  0 $\Omega$ & TBD \\ 
        \cline{6-9} 
        &  &  &  &  & 12 & N.O. &  0 $\Omega$ &  \\ 
        \hline 
        &  &  &  &  & 2 & N.C. &  Open & Open \\ 
        \cline{6-9} 
        7 & RIO & RIO\_VOLT\_SDAR & RIO\_DSP\_+3V3 & P2 & 4 & COM &  0 $\Omega$ & SIGN08150 \\ 
        \cline{6-9} 
        &  &  &  &  & 6 & N.O. &  0 $\Omega$ & Open \\ 
        \hline 
    \end{tabular}%
    \end{adjustwidth}
        %}%
    \caption{Verkabelung der ersten Relaisplatine an X400/PortA}
    \label{tab:x400}
    \end{table}

    \subsection{Even more stuff}

    Just to illustrate that the margins are now their old selves again. \lipsum[5]

\end{document}

Output:

enter image description here

BTW your table will look better with a bit more vertical space. Try for example \renewcommand{\arraystretch}{1.25}.

Related Question