Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8305919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:13:33+00:00 2026-06-08T18:13:33+00:00

I am using the dprint package with knitr , mainly so that I can

  • 0

I am using the dprint package with knitr , mainly so that I can highlight rows from a table, which I have got working, but the output image leaves a fairly large space for a footnote, and it is taking up unnecessary space.

Is there away to get rid of it?

Also since I am fairly new to dprint, if anybody has better ideas/suggestions as to how to highlight tables and make them look pretty without any footnotes… or ways to tidy up my code that would be great!

An example of the Rmd file code is below…

```{r fig.height=10, fig.width=10, dev='jpeg'}
library("dprint")
k <- data.frame(matrix(1:100, 10,10))
CBs <- style(frmt.bdy=frmt(fontfamily="HersheySans"), frmt.tbl=frmt(bty="o", lwd=1),
        frmt.col=frmt(fontfamily="HersheySans", bg="khaki", fontface="bold", lwd=2, bty="_"),
        frmt.grp=frmt(fontfamily="HersheySans",bg="khaki", fontface="bold"),
        frmt.main=frmt(fontfamily="HersheySans", fontface="bold", fontsize=12),
        frmt.ftn=frmt(fontfamily="HersheySans"),
        justify="right", tbl.buf=0)

x <- dprint(~., data=k,footnote=NA, pg.dim=c(10,10), margins=c(0.2,0.2,0.2,0.2), 
              style=CBs, row.hl=row.hl(which(k[,1]==5), col='red'), 
               fit.width=TRUE, fit.height=TRUE,  
                showmargins=TRUE, newpage=TRUE, main="TABLE TITLE")

```

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T18:13:34+00:00Added an answer on June 8, 2026 at 6:13 pm

    So here’s my solution…with some examples…

    I’ve just copied and pasted my Rmd file to demonstrate how to use it.

    you should be able to just copy and paste it into a blank Rmd file and then knit to HTML to see the results…

    Ideally what I would have liked would have been to make it all one nice neat function rather than splitting it up into two (i.e. setup.table & print.table) but since chunk options can’t be changed mid chunk as suggested by Yihui, it had to be split up into two functions…

    `dprint` +  `knitr` Examples to create table images
    ===========
    
    ```{r}
    library(dprint)
    # creating the sytle object to be used
    CBs <- style(frmt.bdy=frmt(fontfamily="HersheySans"), 
                 frmt.tbl=frmt(bty="o", lwd=1),
            frmt.col=frmt(fontfamily="HersheySans", bg="khaki", 
                          fontface="bold", lwd=2, bty="_"),
            frmt.grp=frmt(fontfamily="HersheySans",bg="khaki", 
                          fontface="bold"),
            frmt.main=frmt(fontfamily="HersheySans", fontface="bold", 
                           fontsize=12),
            frmt.ftn=frmt(fontfamily="HersheySans"),
            justify="right", tbl.buf=0)
    
    # creating a setup function to setup printing a table (will probably put this function into my .Rprofile file)
    setup.table <- function(df,width=10, style.obj='CBs'){
      require(dprint)
      table.style <- get(style.obj)
      a <- tbl.struct(~., df)
      b <- char.dim(a, style=table.style)
      p <- pagelayout(dtype = "rgraphics", pg.dim = NULL, margins = NULL)
      f <- size.simp(a[[1]], char.dim.obj=b, loc.y=0, pagelayout=p)
      # now to work out the natural table width to height ratio (w.2.h.r) GIVEN the style
      w.2.h.r <- as.numeric(f$tbl.width/(f$tbl.height +b$linespace.col+ b$linespace.main))
      height <- width/w.2.h.r
    
      table.width <- width
      table.height <- height
    
      # Setting chunk options to have right fig dimensions for the next chunk
      opts_chunk$set('fig.width'=as.numeric(width+0.1))
      opts_chunk$set('fig.height'=as.numeric(height+0.1))
    
      # assigning relevant variables to be used when printing
      assign("table.width",table.width, envir=.GlobalEnv)
      assign("table.height",table.height, envir=.GlobalEnv)
      assign("table.style", table.style, envir=.GlobalEnv)
    }
    
    # function to print the table (will probably put this function into my .Rprofile file as well)
    print.table <- function(df, row.2.hl='2012-04-30', colour='lightblue',...) {
      x <-dprint(~., data=df, style=table.style, pg.dim=c(table.width,table.height), ..., newpage=TRUE,fit.width=TRUE, row.hl=row.hl(which(df[,1]==row.2.hl), col=colour))
    }
    ```
    
    ```{r}
    # Giving it a go!
    # Setting up two differnt size tables
    small.df <- data.frame(matrix(1:100, 10,10))
    big.df <- data.frame(matrix(1:800,40,20))
    ```
    
    
    ```{r}
    # Using the created setup.table function
    setup.table(df=small.df, width=10, style.obj='CBs')
    ```
    
    ```{r}
    # Using the print.table function
    print.table(small.df,4,'lightblue',main='table title string') # highlighting row 4
    ```
    
    ```{r}
    setup.table(big.df,13,'CBs') # now setting up a large table
    ```
    
    ```{r}
    print.table(big.df,38,'orange', main='the big table!') # highlighting row 38 in orange
    ```
    
    ```{r}
    d <- style() # the default style this time will be used
    setup.table(big.df,15,'d')
    ```
    
    ```{r}
    print.table(big.df, 23, 'indianred1') # this time higlihting row 23
    ```
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using android 2.3.3, I have a background Service which has a socket connection. There's
Using MVC2 I have an AJAX form which is posting to a bound model.
Using Delphi 2010. I am looking for (possibly) a function or procedure which can
Using Java,I have to fetch multiple sets of values from an XML file to
Using report builder 3.0, I have a report that queries a cube. How do
Using CRM 4, I have an entity form that contains a tab with an
Using TortoiseSVN against VisualSVN I delete a source file that I should not have
Using a populated Table Type as the source for a TSQL-Merge. I want to
using this http://bl.ocks.org/950642 we can see how to add images to nodes, the question
Using Location.getBearing(); I seem to get randomly changing bearings. Aka, I can turn the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.