问题

问题

问题

我使用 tikz 创建了一个网络图,显示了集线器的行为。将图片插入 kaobook 类的侧边距时,图片太小了。我尝试通过在 \includegraphics 中缩放它来将其放大,但它没有任何变化。我也尝试过缩放 tikz 图片环境,但是一旦达到一定大小,它就不会显示在边距中。

资源

班级

kaobook 类 - Latex 模板

Kaobook 类 - Github

矢量网络拓扑图像

思科网络图标

文件

主文本

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% kaobook
% LaTeX Template
% Version 1.2 (4/1/2020)
%
% This template originates from:
% https://www.LaTeXTemplates.com
%
% For the latest template development version and to make contributions:
% https://github.com/fmarotta/kaobook
%
% Authors:
% Federico Marotta ([email protected])
% Based on the doctoral thesis of Ken Arroyo Ohori (https://3d.bk.tudelft.nl/ken/en)
% and on the Tufte-LaTeX class.
% Modified for LaTeX Templates by Vel ([email protected])
%
% License:
% CC0 1.0 Universal (see included MANIFEST.md file)
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%----------------------------------------------------------------------------------------
%   PACKAGES AND OTHER DOCUMENT CONFIGURATIONS
%----------------------------------------------------------------------------------------

\documentclass[
    fontsize=10pt, % Base font size
    twoside=false, % Use different layouts for even and odd pages (in particular, if twoside=true, the margin column will be always on the outside)
    %open=any, % If twoside=true, uncomment this to force new chapters to start on any page, not only on right (odd) pages
    %chapterprefix=true, % Uncomment to use the word "Chapter" before chapter numbers everywhere they appear
    %chapterentrydots=true, % Uncomment to output dots from the chapter name to the page number in the table of contents
    numbers=noenddot, % Comment to output dots after chapter numbers; the most common values for this option are: enddot, noenddot and auto (see the KOMAScript documentation for an in-depth explanation)
    %draft=true, % If uncommented, rulers will be added in the header and footer
    %overfullrule=true, % If uncommented, overly long lines will be marked by a black box; useful for correcting spacing problems
]{kaobook}

% Set the language
\usepackage[english]{babel} % Load characters and hyphenation
\usepackage[english=british]{csquotes} % English quotes

% Load packages for testing
\usepackage{blindtext}
%\usepackage{showframe} % Uncomment to show boxes around the text area, margin, header and footer
%\usepackage{showlabels} % Uncomment to output the content of \label commands to the document where they are used

% Load the bibliography package
\usepackage{styles/kaobiblio}
\addbibresource{main.bib} % Bibliography file

% Load mathematical packages for theorems and related environments. NOTE: choose only one between 'mdftheorems' and 'plaintheorems'.
\usepackage{styles/mdftheorems}
%\usepackage{styles/plaintheorems}

\graphicspath{{examples/documentation/images/}{images/}} % Paths in which to look for images

\makeindex[columns=3, title=Alphabetical Index, intoc] % Make LaTeX produce the files required to compile the index

\makeglossaries % Make LaTeX produce the files required to compile the glossary

\makenomenclature % Make LaTeX produce the files required to compile the nomenclature

% Reset sidenote counter at chapters
%\counterwithin*{sidenote}{chapter}

%----------------------------------------------------------------------------------------

\begin{document}

%----------------------------------------------------------------------------------------
%   BOOK INFORMATION
%----------------------------------------------------------------------------------------

\titlehead{TeX Exchange Example}
%\subject{This document will help you pass Network+}

\title[TeX Exchange Example]{TeX Exchange Example}
\subtitle{Help Needed}

\author[nescafegold]{nescafegold \thanks{A LaTeX Lover}}

\date{\today}

\publishers{Publisher: Myself}

%----------------------------------------------------------------------------------------

\frontmatter % Denotes the start of the pre-document content, uses roman numerals

%----------------------------------------------------------------------------------------
%   OPENING PAGE
%----------------------------------------------------------------------------------------

%\makeatletter
%\extratitle{
%   % In the title page, the title is vspaced by 9.5\baselineskip
%   \vspace*{9\baselineskip}
%   \vspace*{\parskip}
%   \begin{center}
%       % In the title page, \huge is set after the komafont for title
%       \usekomafont{title}\huge\@title
%   \end{center}
%}
%\makeatother

%----------------------------------------------------------------------------------------
%   COPYRIGHT PAGE
%----------------------------------------------------------------------------------------

\makeatletter
\uppertitleback{\@titlehead} % Header

\lowertitleback{
    \textbf{Disclaimer}\\
    You can edit this page to suit your needs. For instance, here we have a no copyright statement, a colophon and some other information. This page is based on the corresponding page of Ken Arroyo Ohori's thesis, with minimal changes.
    
    \medskip
    
    \textbf{No copyright}\\
    \cczero\ This book is released into the public domain using the CC0 code. To the extent possible under law, I waive all copyright and related or neighbouring rights to this work.
    
    To view a copy of the CC0 code, visit: \\\url{http://creativecommons.org/publicdomain/zero/1.0/}
    
    \medskip
    
    \textbf{Colophon} \\
    This document was typeset with the help of \href{https://sourceforge.net/projects/koma-script/}{\KOMAScript} and \href{https://www.latex-project.org/}{\LaTeX} using the \href{https://github.com/fmarotta/kaobook/}{kaobook} class.
    
    The source code of this book is available at:\\\url{https://github.com/fmarotta/kaobook}
    
    (You are welcome to contribute!)
    
    \medskip
    
    \textbf{Publisher} \\
    First printed in May 2019 by \@publishers
}
\makeatother

%----------------------------------------------------------------------------------------
%   DEDICATION
%----------------------------------------------------------------------------------------

\dedication{
    The harmony of the world is made manifest in Form and Number, and the heart and soul and all the poetry of Natural Philosophy are embodied in the concept of mathematical beauty.\\
    \flushright -- D'Arcy Wentworth Thompson
}

%----------------------------------------------------------------------------------------
%   OUTPUT TITLE PAGE AND PREVIOUS
%----------------------------------------------------------------------------------------

% Note that \maketitle outputs the pages before here

% If twoside=false, \uppertitleback and \lowertitleback are not printed
% To overcome this issue, we set twoside=semi just before printing the title pages, and set it back to false just after the title pages
\KOMAoptions{twoside=semi}
\maketitle
\KOMAoptions{twoside=false}

%----------------------------------------------------------------------------------------
%   PREFACE
%----------------------------------------------------------------------------------------

%\input{chapters/preface.tex}

%----------------------------------------------------------------------------------------
%   TABLE OF CONTENTS & LIST OF FIGURES/TABLES
%----------------------------------------------------------------------------------------

\begingroup % Local scope for the following commands

% Define the style for the TOC, LOF, and LOT
%\setstretch{1} % Uncomment to modify line spacing in the ToC
%\hypersetup{linkcolor=blue} % Uncomment to set the colour of links in the ToC
\setlength{\textheight}{23cm} % Manually adjust the height of the ToC pages

% Turn on compatibility mode for the etoc package
\etocstandarddisplaystyle % "toc display" as if etoc was not loaded
\etocstandardlines % toc lines as if etoc was not loaded

\tableofcontents % Output the table of contents

\listoffigures % Output the list of figures

% Comment both of the following lines to have the LOF and the LOT on different pages
\let\cleardoublepage\bigskip
\let\clearpage\bigskip

\listoftables % Output the list of tables

\endgroup

%----------------------------------------------------------------------------------------
%   MAIN BODY
%----------------------------------------------------------------------------------------

\mainmatter % Denotes the start of the main document content, resets page numbering and uses arabic numbers
\setchapterstyle{kao} % Choose the default chapter heading style

\blindtext

\begin{marginfigure}[-5.5cm]
  \includegraphics[scale=2]{../images/hubs.pdf}
    \caption[hub]{Client and Server relationship Example Using a Web Browser and Web Server}
  \labfig{marginhub}
\end{marginfigure}

\blindtext

\blindtext

\blindtext
%\pagelayout{wide} % No margins
%\addpart{Class Options, Commands and Environments}
%\pagelayout{margin} % Restore margins

%\input{chapters/options.tex}
%\input{chapters/textnotes.tex}
%\input{chapters/figsntabs.tex}
%\input{chapters/references.tex}

%\pagelayout{wide} % No margins
%\addpart{Design and Additional Features}
%\pagelayout{margin} % Restore margins

%\input{chapters/layout.tex}
%\input{chapters/mathematics.tex}

%\appendix % From here onwards, chapters are numbered with letters, as is the appendix convention

%\pagelayout{wide} % No margins
%\addpart{Appendix}
%\pagelayout{margin} % Restore margins

%\input{chapters/appendix.tex}

%----------------------------------------------------------------------------------------

%\backmatter % Denotes the end of the main document content
%\setchapterstyle{plain} % Output plain chapters from this point onwards

%----------------------------------------------------------------------------------------
%   BIBLIOGRAPHY
%----------------------------------------------------------------------------------------

% The bibliography needs to be compiled with biber using your LaTeX editor, or on the command line with 'biber main' from the template directory

\defbibnote{bibnote}{Here are the references in citation order.\par\bigskip} % Prepend this text to the bibliography
\printbibliography[heading=bibintoc, title=Bibliography, prenote=bibnote] % Add the bibliography heading to the ToC, set the title of the bibliography and output the bibliography note

%----------------------------------------------------------------------------------------
%   NOMENCLATURE
%----------------------------------------------------------------------------------------

%% The nomenclature needs to be compiled on the command line with 'makeindex main.nlo -s nomencl.ist -o main.nls' from the template directory

%\nomenclature{$c$}{Speed of light in a vacuum inertial frame}
%\nomenclature{$h$}{Planck constant}

%\renewcommand{\nomname}{Notation} % Rename the default 'Nomenclature'
%\renewcommand{\nompreamble}{The next list describes several symbols that will be later used within the body of the document.} % Prepend this text to the nomenclature

%\printnomenclature % Output the nomenclature

%----------------------------------------------------------------------------------------
%   GREEK ALPHABET
%   Originally from https://gitlab.com/jim.hefferon/linear-algebra
%----------------------------------------------------------------------------------------

%\vspace{1cm}

%{\usekomafont{chapter}Greek Letters with Pronounciation} \\[2ex]
%\begin{center}
%   \newcommand{\pronounced}[1]{\hspace*{.2em}\small\textit{#1}}
%   \begin{tabular}{l l @{\hspace*{3em}} l l}
%       \toprule
%       Character & Name & Character & Name \\ 
%       \midrule
%       $\alpha$ & alpha \pronounced{AL-fuh} & $\nu$ & nu \pronounced{NEW} \\
%       $\beta$ & beta \pronounced{BAY-tuh} & $\xi$, $\Xi$ & xi \pronounced{KSIGH} \\ 
%       $\gamma$, $\Gamma$ & gamma \pronounced{GAM-muh} & o & omicron \pronounced{OM-uh-CRON} \\
%       $\delta$, $\Delta$ & delta \pronounced{DEL-tuh} & $\pi$, $\Pi$ & pi \pronounced{PIE} \\
%       $\epsilon$ & epsilon \pronounced{EP-suh-lon} & $\rho$ & rho \pronounced{ROW} \\
%       $\zeta$ & zeta \pronounced{ZAY-tuh} & $\sigma$, $\Sigma$ & sigma \pronounced{SIG-muh} \\
%       $\eta$ & eta \pronounced{AY-tuh} & $\tau$ & tau \pronounced{TOW (as in cow)} \\
%       $\theta$, $\Theta$ & theta \pronounced{THAY-tuh} & $\upsilon$, $\Upsilon$ & upsilon \pronounced{OOP-suh-LON} \\
%       $\iota$ & iota \pronounced{eye-OH-tuh} & $\phi$, $\Phi$ & phi \pronounced{FEE, or FI (as in hi)} \\
%       $\kappa$ & kappa \pronounced{KAP-uh} & $\chi$ & chi \pronounced{KI (as in hi)} \\
%       $\lambda$, $\Lambda$ & lambda \pronounced{LAM-duh} & $\psi$, $\Psi$ & psi \pronounced{SIGH, or PSIGH} \\
%       $\mu$ & mu \pronounced{MEW} & $\omega$, $\Omega$ & omega \pronounced{oh-MAY-guh} \\
%       \bottomrule
%   \end{tabular} \\[1.5ex]
%   Capitals shown are the ones that differ from Roman capitals.
%\end{center}

%----------------------------------------------------------------------------------------
%   GLOSSARY
%----------------------------------------------------------------------------------------

%% The glossary needs to be compiled on the command line with 'makeglossaries main' from the template directory

%\newglossaryentry{computer}{
%   name=computer,
%   description={is a programmable machine that receives input, stores and manipulates data, and provides output in a useful format}
%}

%% Glossary entries (used in text with e.g. \acrfull{fpsLabel} or \acrshort{fpsLabel})
%\newacronym[longplural={Frames per Second}]{fpsLabel}{FPS}{Frame per Second}
%\newacronym[longplural={Tables of Contents}]{tocLabel}{TOC}{Table of Contents}

%\setglossarystyle{listgroup} % Set the style of the glossary (see https://en.wikibooks.org/wiki/LaTeX/Glossary for a reference)
%\printglossary[title=Special Terms, toctitle=List of Terms] % Output the glossary, 'title' is the chapter heading for the glossary, toctitle is the table of contents heading

%----------------------------------------------------------------------------------------
%   INDEX
%----------------------------------------------------------------------------------------

%% The index needs to be compiled on the command line with 'makeindex main' from the template directory

%\printindex % Output the index

%----------------------------------------------------------------------------------------
%   BACK COVER
%----------------------------------------------------------------------------------------

%% If you have a PDF/image file that you want to use as a back cover, uncomment the following lines

%%\clearpage
%%\thispagestyle{empty}
%%\null%
%%\clearpage
%%\includepdf{cover-back.pdf}

%----------------------------------------------------------------------------------------

\end{document}

hub.tex - Tikz

请原谅这段糟糕的代码,这是我的第一幅 tikz 绘图(欢迎提出任何改进建议,但与问题无关)。

\documentclass{article}

\usepackage{graphicx}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
%\begin{tikzpicture}[scale=2, transform shape]

% Network Equipment
  \node[inner sep=2pt, label=above:{\tiny{hub}}] (hub) at (0,0) 
    {\includegraphics[scale=1]{small-hub.pdf}};
\node[inner sep=2pt, label=above:{\tiny{PC-2}}] (pc) at (2.5,3)
    {\includegraphics[scale=1]{pc.pdf}};
\node[inner sep=4pt, label=below:{\tiny{Server}}] (server) at (-2.6,-3)
    {\includegraphics[scale=0.5]{server.pdf}};
\node[inner sep=2pt, label=below:{\tiny{PC-3}}] (pc-2) at (2.5,-3)
    {\includegraphics[scale=1]{pc.pdf}};
\node[inner sep=2pt, label=above:{\tiny{PC-1}}] (pc-3) at (-2.5,3)
    {\includegraphics[scale=1]{pc.pdf}};

% Ethernet Cables
\draw[-, thick] (pc) -- (hub);
\draw[-, thick] (pc-2) -- (hub);
\draw[-, thick] (pc-3) -- (hub);
\draw[-, thick] (server) -- (hub);

% Key
\draw (-1.6,5.4) rectangle (1.4,4.5);

\node[text width=3cm] at (1.2,5.2) {\tiny{KEY:}};

\node[text width=3cm] at (0.8,5.0) {\tiny{Ethernet Cable}};
\draw[thick] (-1.5,5.0) -- (-0.8,5.0);

\node[text width=3cm] at (0.8,4.7) {\tiny{Information Travel}};
\draw[red, dashed] (-1.5,4.7) -- (-0.8,4.7);


\draw[->, red, dashed] (hub.north east) -- (pc.south);
\draw[->, red, dashed] (hub.north west) -- (pc-3.south);
\draw[->, red, dashed] (hub.south east) -- (pc-2.north);
\draw[->, red, dashed] (server.north) -- (hub.south west);

\end{tikzpicture}
\end{document}

最终结果

主文本

示例主文档

中心.pdf

tikz 绘图示例

任何帮助是极大的赞赏

解决方案

感谢所有回答的人,将类改为 \documentclass{standalone} 而不是 article(按照 Torbjørn T. 的建议)修复了裁剪问题,使其完美地贴合图像。这导致图片在插入文档时被放大了很多。

结果如下:

tikz-解决方案

除了将文档类别更改为 \documentclass{standalone} 之外,我还将文本放大了一些,以便于阅读。我可能会进一步更改大小和间距,使其更大一些,因为更改比例仍然不起作用。如果有人感兴趣,这里是 tikz 代码。

\documentclass{standalone}

\usepackage{graphicx}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
%\begin{tikzpicture}[scale=2, transform shape]

% Network Equipment
  \node[inner sep=2pt, label=above:{hub}] (hub) at (0,0) 
    {\includegraphics[scale=1]{small-hub.pdf}};
\node[inner sep=2pt, label=above:{PC-2}] (pc) at (2.5,3)
    {\includegraphics[scale=1]{pc.pdf}};
\node[inner sep=4pt, label=below:{Server}] (server) at (-2.6,-3)
    {\includegraphics[scale=0.5]{server.pdf}};
\node[inner sep=2pt, label=below:{PC-3}] (pc-2) at (2.5,-3)
    {\includegraphics[scale=1]{pc.pdf}};
\node[inner sep=2pt, label=above:{PC-1}] (pc-3) at (-2.5,3)
    {\includegraphics[scale=1]{pc.pdf}};

% Ethernet Cables
\draw[-, thick] (pc) -- (hub);
\draw[-, thick] (pc-2) -- (hub);
\draw[-, thick] (pc-3) -- (hub);
\draw[-, thick] (server) -- (hub);

% Key
\draw (-1.6,5.5) rectangle (2.3,4.5);

\node[text width=3cm] at (1.2,5.3) {\large{KEY:}};

\node[text width=3cm] at (0.8,5.0) {Ethernet Cable};
\draw[thick] (-1.5,5.0) -- (-0.8,5.0);

\node[text width=3cm] at (0.8,4.7) {Information Travel};
\draw[red, dashed] (-1.5,4.7) -- (-0.8,4.7);


\draw[->, red, dashed] (hub.north east) -- (pc.south);
\draw[->, red, dashed] (hub.north west) -- (pc-3.south);
\draw[->, red, dashed] (hub.south east) -- (pc-2.north);
\draw[->, red, dashed] (server.north) -- (hub.south west);

\end{tikzpicture}
\end{document}

相关内容